HttpWebRequest.GetResponse failure

S

set

Hi All.
I have a problem with a small app that works on PC but doesn't work on WM
5.0 (iPAQ rx1950).
I detached the problem into a small function.

public void testAuth()
{
for (int i = 0; i < 5; ++i)
{
try
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(URL);
req.Timeout = 5000;

WebResponse resp = req.GetResponse();

StreamReader reader = new
StreamReader(resp.GetResponseStream());

string pageText = reader.ReadToEnd();

reader.Close();
resp.Close();
}
catch (WebException e)
{
DebugWriteLine("testAuth: web exception: " + e.Message +
" " + e.Status);
}
catch (Exception e)
{
DebugWriteLine("testAuth: exception: " + e.Message);
}
}
}



First iteration is OK, but for second and third I get

testAuth: web exception: The remote server returned an error: (404) Not
Found. ProtocolError

and for all subsequent tries I get

testAuth: web exception: The operation has timed-out. Timeout.


In the same time Internet Explorer works ok and shows URL response correctly
any num of times.

What could be a problem?

Thanks.
 
W

Will Chapman

set said:
Hi All.
I have a problem with a small app that works on PC but doesn't work on WM
5.0 (iPAQ rx1950).
I detached the problem into a small function.

public void testAuth()
{
for (int i = 0; i < 5; ++i)
{
try
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(URL);
req.Timeout = 5000;

WebResponse resp = req.GetResponse();

StreamReader reader = new
StreamReader(resp.GetResponseStream());

string pageText = reader.ReadToEnd();

reader.Close();
resp.Close();
}
catch (WebException e)
{
DebugWriteLine("testAuth: web exception: " + e.Message +
" " + e.Status);
}
catch (Exception e)
{
DebugWriteLine("testAuth: exception: " + e.Message);
}
}
}



First iteration is OK, but for second and third I get

testAuth: web exception: The remote server returned an error: (404) Not
Found. ProtocolError

and for all subsequent tries I get

testAuth: web exception: The operation has timed-out. Timeout.


In the same time Internet Explorer works ok and shows URL response correctly
any num of times.

What could be a problem?
NOt quite the same scenario but I experienced problems with
CF HttpWebRequest until I filled out a few headers, thus:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "Get";
req.ContentType = "text/plain";
req.UserAgent = "iPaq6515/.NETCF";
req.Accept = "*/*";
req.ProtocolVersion = HttpVersion.Version10;
req.Timeout = 5000;

Hope this helps:

Regards


Will Chapman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top