Problem with HttpWebRequest class...

D

Darryl

I'm trying to use the HttpWebRequest class to retrieve XML generated by a
jsp page, but an 'The remote server returned an error: (500) Internal Server
Error' exception is thrown when I call the WebRequest's GetResponse()
method. If I type the URL into the browser (IE), the correct XML is
returned. Similarly, the correct XML is returned if I open the URL using the
WebClient class' OpenRead() method. Here's the code that I'm using:

//The following code results in the exception:
string strURL =
"http://serverName/appDir/filename.jsp?accountName=acc&strParam=param1";
System.Uri myURI = new System.Uri(strURL, false); //I've also tried
setting the second parameter to 'true'.
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(myURI);
myRequest.Method = "GET";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Accept = "*/*";
myRequest.Timeout = 30000;
myRequest.CookieContainer = m_cookieContainer; //Setting this in order
to pass same session id to server.
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//Exception is thrown here.
StreamReader myReader = new
StreamReader(myResponse.GetResponseStream());
string strResponse = myReader.ReadToEnd();
myResponse.Close();
myReader.Close();

//The following code works correctly:
System.Net.WebClient wc = new WebClient();
string strURL =
"http://serverName/appDir/filename.jsp?accountName=acc&strParam=param1";
System.IO.Stream myStream = wc.OpenRead(strURL);
StreamReader myReader = new StreamReader(myStream);
string s = myReader.ReadToEnd();
myStream.Close();
myReader.Close();

Any ideas would be greatly appreciated.

Darryl R.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top