如何让HttpWebRequest与Netduino一起使用?它给了我System.NotSupportedException

时间:2015-02-13 16:03:24

标签: .net http frameworks netduino

我试图从我的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);

1 个答案:

答案 0 :(得分:0)

在致电.Create(...)方法时,要么传递Uri的实例,要么包含protoctol,即http://example.com:8080