S
safdarhhaider
Hi,
I'm using HttpWebRequest to get some data from an ASP page off a
Windows 2000 Professional machine running IIS.
I start my application in debug mode (running on Visual Studio .NET
2003 + PocketPC 2002 Emulator) and execute the follwing code...
private void WeRequestTest()
{
string responseData = "";
try
{
// Create the WebRequest object and set the URL
HttpWebRequest webReq =
(HttpWebRequest)WebRequest.Create("http://mymachine/test.asp");
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.Method = "POST";
string postData = "TestParam=123" ;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytePostData = encoding.GetBytes(postData);
webReq.ContentLength = bytePostData.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(bytePostData, 0, bytePostData.Length);
newStream.Close();
// Get the result sent by the Server
WebResponse webResp = webReq.GetResponse();
Stream respStream = webResp.GetResponseStream();
StreamReader streamReader = new StreamReader(respStream,
Encoding.ASCII);
responseData = streamReader.ReadToEnd();
streamReader.Close();
webResp.Close();
MessageBox.Show(responseData);
}
catch(Exception excp)
{
MessageBox.Show(excp.Message);
}
}
It just sits on the line...
Stream newStream = webReq.GetRequestStream();
and finally errors out saying "unable to connect to the remote server"
I stop the application, start it again and run the code again and it
works fine this time arround and also on subsequest attempts. Its just
the first time that it does'nt work.
Now when things are working fine, if I close the application, come back
say after an hour or so, try it again and guess what? yeah, it fails
again on first attempt, but again on the subsequest attempts it works
fine.
This behaviour is very consistent and i'm always able to reproduce it.
I wonder if somebody has had similar problem with HttpWebRequest and
was able to resolve it.
I have modified the URL to simplify it here in the sample code, rest of
the code is exactly the same. The real URL points to a test asp page on
my computer and i'm using my computer's name instead of "localhost" in
the url.
I'll greatly appreciate any thoughts that can help me resolve this
issue, Thanks.
SAFDAR
-- Some people are wise, others are otherwise
I'm using HttpWebRequest to get some data from an ASP page off a
Windows 2000 Professional machine running IIS.
I start my application in debug mode (running on Visual Studio .NET
2003 + PocketPC 2002 Emulator) and execute the follwing code...
private void WeRequestTest()
{
string responseData = "";
try
{
// Create the WebRequest object and set the URL
HttpWebRequest webReq =
(HttpWebRequest)WebRequest.Create("http://mymachine/test.asp");
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.Method = "POST";
string postData = "TestParam=123" ;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytePostData = encoding.GetBytes(postData);
webReq.ContentLength = bytePostData.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(bytePostData, 0, bytePostData.Length);
newStream.Close();
// Get the result sent by the Server
WebResponse webResp = webReq.GetResponse();
Stream respStream = webResp.GetResponseStream();
StreamReader streamReader = new StreamReader(respStream,
Encoding.ASCII);
responseData = streamReader.ReadToEnd();
streamReader.Close();
webResp.Close();
MessageBox.Show(responseData);
}
catch(Exception excp)
{
MessageBox.Show(excp.Message);
}
}
It just sits on the line...
Stream newStream = webReq.GetRequestStream();
and finally errors out saying "unable to connect to the remote server"
I stop the application, start it again and run the code again and it
works fine this time arround and also on subsequest attempts. Its just
the first time that it does'nt work.
Now when things are working fine, if I close the application, come back
say after an hour or so, try it again and guess what? yeah, it fails
again on first attempt, but again on the subsequest attempts it works
fine.
This behaviour is very consistent and i'm always able to reproduce it.
I wonder if somebody has had similar problem with HttpWebRequest and
was able to resolve it.
I have modified the URL to simplify it here in the sample code, rest of
the code is exactly the same. The real URL points to a test asp page on
my computer and i'm using my computer's name instead of "localhost" in
the url.
I'll greatly appreciate any thoughts that can help me resolve this
issue, Thanks.
SAFDAR
-- Some people are wise, others are otherwise