LouisVA

I am having a problem with using HttpWebRequest on a PPC2003 device and hope someone could help as I am at wit¡¯s end. I really need to find a solution to this¡­

Setup details are:

  • Windows XP SP2 PC with IP 10.0.0.100 assigned by ADSL router
  • ActiveSync 4.5
  • I have the PPC2003 device hooked up to a USB cradle
  • I can access the internet on the device (with PIE) via the ActiveSync connection.
  • If I have IIS running on the PC, I can access pages served by IIS from the device (with PIE)

However, if I stop IIS and use my own HttpServer on port 80, I get errors. I get the ProtocolError / BadRequest (Invalid Hostname) error.

Here is what I have done:

With IIS running

  • Access a web page on the PC from PIE. E.g. http://10.0.0.100/dir/file.html. This works correctly so it means that there is connectivity between device and PC through ActiveSync
  • From a PDA test app, GET the page from the PC using the HttpWebRequest class:

WebRequest Request = HttpWebRequest.Create(¡°http://10.0.0.100:80/dir/file.html¡±);

Request.Method = "GET";

WebResponse Response = Request.GetResponse();

Stream ResponseStream = Response.GetResponseStream();

TextReader RequestReader = new StreamReader(ResponseStream);

string ResponseText = RequestReader.ReadToEnd();

With the above code and IIS running, I get the contents of the requested file. Good so far

Now I stop IIS and start my own HTTP server implemented as follows:

private void StartListener()

{

hl = new System.Net.HttpListener();

hl.Prefixes.Add("http://10.0.0.100:80/");

hl.Start();

IAsyncResult Result = hl.BeginGetContext(new AsyncCallback(WebRequestCallback), hl);

}

private void WebRequestCallback(IAsyncResult AResult)

{

// Get the context object

HttpListenerContext Context = hl.EndGetContext(AResult);

// Immediately set up the next context

hl.BeginGetContext(new AsyncCallback(WebRequestCallback), hl);

// ProcessRequest

Stream RequestStream = Context.Request.InputStream;

TextReader RequestReader = new StreamReader(RequestStream);

string RequestText = RequestReader.ReadToEnd();

RequestReader.Close();

RequestStream.Close();

string ResponseText = "Hello World";

// Respond to message

HttpListenerResponse Response = Context.Response;

byte[] ResponseBuffer = System.Text.Encoding.UTF8.GetBytes(ResponseText);

Response.ContentLength64 = ResponseBuffer.Length;

Stream ResponseStream = Response.OutputStream;

ResponseStream.Write(ResponseBuffer, 0, ResponseBuffer.Length);

ResponseStream.Close();

}

If I now use Firefox on the PC and request the URI http://10.0.0.100/, I get Hello World as I expected. So it means that my HttpServer works.

However if I use PIE on the device and request http://10.0.0.100/, I get the Bad Request (Invalid Hostname) error. If I stop my HttpServer, I get a timeout on PIE. This shows me that there is probably comms between PIE and my HttpServer, but something is amiss¡­

My PDA test app that works with IIS does not work with my own HttpServer. IIS is set up to allow anonymous access (and manage the anon password) , so this is probably why everything works when IIS is running. Now when I run my own HttpServer there is probably an authentication issue, because I do not set the client request credentials.

How do I set what authentication is used by my HttpServer

Why does this work with WM5 and not PPC 2003

How do I get around this

Many thanks to anyone willing to help me¡­.



Re: Smart Devices General HttpWebRequest problem and really desperate

Higgs Boson

Firefox will be a lot more forgiving than PIE, I would telnet (or equiv) the responses from the servers (IIS / RollYourOwn) using the same source page, and diff them. Then try getting your server as close to the IIS response as possible.

Are you sure its neccesary to roll your own HTTP server IIS is pretty flexible these days....




Re: Smart Devices General HttpWebRequest problem and really desperate

LouisVA

Thanks for the feedback Higgs. I am not sure how to telnet the responses as you describe. Anywhere I can read up on it

My situation is that I am developing a mobile app for a customer that has implemented their HTTP (SOAP) -based application server from the ground up. Maybe I should check my client app against their server and not use PIE at all. Maybe their server's response is also different and my app would actually work...

Would appreciate help to see the various server responses with telnet though....

Thanks again