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?ac countName=acc&s trParam=param1" ;
System.Uri myURI = new System.Uri(strU RL, false); //I've also tried
setting the second parameter to 'true'.
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Cre ate(myURI);
myRequest.Metho d = "GET";
myRequest.Conte ntType = "applicatio n/x-www-form-urlencoded";
myRequest.Accep t = "*/*";
myRequest.Timeo ut = 30000;
myRequest.Cooki eContainer = m_cookieContain er; //Setting this in order
to pass same session id to server.
HttpWebResponse myResponse = (HttpWebRespons e)myRequest.Get Response();
//Exception is thrown here.
StreamReader myReader = new
StreamReader(my Response.GetRes ponseStream());
string strResponse = myReader.ReadTo End();
myResponse.Clos e();
myReader.Close( );
//The following code works correctly:
System.Net.WebC lient wc = new WebClient();
string strURL =
"http://serverName/appDir/filename.jsp?ac countName=acc&s trParam=param1" ;
System.IO.Strea m myStream = wc.OpenRead(str URL);
StreamReader myReader = new StreamReader(my Stream);
string s = myReader.ReadTo End();
myStream.Close( );
myReader.Close( );
Any ideas would be greatly appreciated.
Darryl R.
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?ac countName=acc&s trParam=param1" ;
System.Uri myURI = new System.Uri(strU RL, false); //I've also tried
setting the second parameter to 'true'.
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Cre ate(myURI);
myRequest.Metho d = "GET";
myRequest.Conte ntType = "applicatio n/x-www-form-urlencoded";
myRequest.Accep t = "*/*";
myRequest.Timeo ut = 30000;
myRequest.Cooki eContainer = m_cookieContain er; //Setting this in order
to pass same session id to server.
HttpWebResponse myResponse = (HttpWebRespons e)myRequest.Get Response();
//Exception is thrown here.
StreamReader myReader = new
StreamReader(my Response.GetRes ponseStream());
string strResponse = myReader.ReadTo End();
myResponse.Clos e();
myReader.Close( );
//The following code works correctly:
System.Net.WebC lient wc = new WebClient();
string strURL =
"http://serverName/appDir/filename.jsp?ac countName=acc&s trParam=param1" ;
System.IO.Strea m myStream = wc.OpenRead(str URL);
StreamReader myReader = new StreamReader(my Stream);
string s = myReader.ReadTo End();
myStream.Close( );
myReader.Close( );
Any ideas would be greatly appreciated.
Darryl R.