我试图从我的netduino发送一个http POST请求,我已经在netduino论坛上了,并且有关于这个能够工作的相互矛盾的报告,这个例外发生在第一行
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("example.com:8080");
string postData = "temperature=" + tempSensor.Temperature;
byte[] data = Encoding.UTF8.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
for (int i = 0; i < 10; i++)
{
stream.Write(data, 0, data.Length);
Thread.Sleep(1000);
}
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Debug.Print(response.StatusDescription);
答案 0 :(得分:0)
在致电.Create(...)
方法时,要么传递Uri
的实例,要么包含protoctol,即http://example.com:8080
。