I posted this question in PocketPC newsgroup with no answer. Hopefully
somebody in this newsgroup can help me.
I have problem with HTTP post in Compact Framework. The code below is
a function I use to post a HTTP message. This code works in Windows XP
always. When I compile the same code to run on an iPaq PocketPC 2003
it works exactly 2 times and then fails afterward at line
"GetResponseStream()" with the exception;
"System.Net.WebException; Could not find resource assembly"
I have tried this code through the ActiveSync USB link and also a
SocketComm compact flash network card on the iPaq with exactly the same
failure after two times working properly. If I quit the application
and run it again it works again for two times and then fails afterward.
I can't figure out why this code works on Windows XP and fails after
exactly two times in an iPaq under Compact Framework. Is there a
resource that is not released in PocketPC? Can failure after 2 times
give a clue what might be wrong? Is there a way to modify the code to
work always? Is there a sample code for proper HTTP Post in PocketPC?
Any help is highly appreciated.
// -----------------------------------------------------
// -----------------------------------------------------
// -- HTTP Post function. Failing line shown ----------
// -----------------------------------------------------
public string HttpPost(string URI, string PostMessage)
{
System.Net.WebResponse resp = null;
try
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.ContentType = "text/xml";
req.Method = "POST";
req.Timeout = 2000; // 2 seconds
byte[] bytes =
System.Text.Encoding.ASCII.GetBytes(PostMessage);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream(); // <-- fails here
after 2 times
os.Write(bytes, 0, bytes.Length);
os.Close();
resp = req.GetResponse();
}
catch (Exception e)
{
string msg = "HTTP Post failed\r\n";
msg += e.ToString();
return msg;
}
if (resp == null) return null;
System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}