I went to the site you provided and downloaded the code, swapped it in for my 'webrequest' class. Modified it slightly for my situation and ran it. It runs fine the first time through but on the second time around it hangs on the line after the debug.print("X4") line. Code shown below. This is a static class. Do the objects created within the class get recreated the second time through the code?
//Developed for the book
// "Getting Started with the Internet of Things", by Cuno Pfister.
// Copyright 2011 Cuno Pfister, Inc., 978-1-4493-9357-1.
//
// Version 4.3, for the .NET Micro Framework release 4.3.
using Microsoft.SPOT;
using System;
using System.IO;
using System.Net;
using System.Text;
namespace App4ReadTemp
{
public static class XivelyClient
{
public static void Send(float ftemp)
{
Debug.Print("time: " + DateTime.Now);
Debug.Print("memory available: " + Debug.GC(true));
try
{
using (var request = CreateRequest(ftemp))
{
request.Timeout = 5000; // 5 seconds
// send request and receive response
Debug.Print("X6");
using (var response =
(HttpWebResponse)request.GetResponse())
{
Debug.Print("X7");
HandleResponse(response);
Debug.Print("X8");
}
}
}
catch (Exception e)
{
Debug.Print(e.ToString());
}
}
static HttpWebRequest CreateRequest(float ftemp)
{
ftemp = (float)(System.Math.Round((double)ftemp));
string Temp = ftemp.ToString();
string postData = "temp1=" + Temp;
byte[] buffer = Encoding.UTF8.GetBytes(postData);
Debug.Print("X1");
var request = (HttpWebRequest)WebRequest.Create(baseUri);
Debug.Print("X2");
// request line
request.Method = "PUT";
// request headers
request.ContentLength = buffer.Length;
request.ContentType = "application/x-www-form-urlencoded";
// request body
Debug.Print("X3");
using (Stream stream = request.GetRequestStream())
{
Debug.Print("X4");
stream.Write(buffer, 0, buffer.Length);
Debug.Print("X5");
}
return request;
}
public static void HandleResponse(HttpWebResponse response)
{
Debug.Print("Status code: " + response.StatusCode);
}
}
}