T
Tom Ruby
Guest
Trying to send data to a web form. It always replies "400".
I can do it from an html page like so:
<form action="https://api.particle.io/v1/devices/4500*****3036/Settings?access_token=hidingthispart" method="POST">
Tell your device what to do!<br>
<br>
<input type="text" name="arg" value="" > The settings string.
<br>
<input type="submit" value="Do it!">
</form>
But not from .net code like so:
string postData = "arg=" + tbMaxChamber.Text + "," + tbMinChamber.Text + "," + tbMeatTarget.Text + "," + tbMeatAlert.Text;
string url = "https://api.particle.io/v1/devices/4500***********63036/Settings?access_token=hidingthispart";
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
lblResponse.Text = (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
lblResults.Text = responseFromServer;
reader.Close();
dataStream.Close();
response.Close();
Perhaps I have to do something different because it's an https?
Continue reading...
I can do it from an html page like so:
<form action="https://api.particle.io/v1/devices/4500*****3036/Settings?access_token=hidingthispart" method="POST">
Tell your device what to do!<br>
<br>
<input type="text" name="arg" value="" > The settings string.
<br>
<input type="submit" value="Do it!">
</form>
But not from .net code like so:
string postData = "arg=" + tbMaxChamber.Text + "," + tbMinChamber.Text + "," + tbMeatTarget.Text + "," + tbMeatAlert.Text;
string url = "https://api.particle.io/v1/devices/4500***********63036/Settings?access_token=hidingthispart";
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
lblResponse.Text = (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
lblResults.Text = responseFromServer;
reader.Close();
dataStream.Close();
response.Close();
Perhaps I have to do something different because it's an https?
Continue reading...