How can I get HttpWebRequest to work with Netduino? It is giving me System.NotSupportedException

277 views Asked by At

I'm trying to send an http POST request from my netduino, I've been on the netduino forum and there is conflicting reports of this being able to work, the exception occurs on the first line

            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

There are 1 answers

0
THX-1138 On

In your call to .Create(...) method, either pass an instance of Uri or include protoctol, i.e. http://example.com:8080.