473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HttpWebRequest Class - Process Exception Message

Hi,

I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I, however, still need to access the response stream from the server as it contains information that I need. Any ideas how I can do that?

Thanks,
Konstantin

try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/myUrl");
myRequest.Method = "GET";
WebResponse response = myRequest.GetResponse();
//If the server returns 5xx status code the next statement executed will be in the catch block
//Nevertheless, I still need the response stream from the server
Stream responseStream = response.GetResponseStream();
}
catch (System.Exception exc)
{
//Process exception
//How can I access the response stream from here?
}

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 19 '05 #1
1 1607
Hi Konstantin,

By default WebRequest will throw an exception. You have to handle the
WebException and use the resulting ex.Response of it to read from to get the
full content from the server.

// *** Return the Response data
HttpWebResponse WebResponse = null;
try
{
WebResponse = (HttpWebResponse) loHttp.GetResponse();
}
catch(WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
WebResponse = (HttpWebResponse) ex.Response ;
}

Hope this helps,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog

"Konstantin" <ia********@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
Hi,

I am using HttpWebRequest class to communicate with remote server. In some
cases the server would return 5xx status code which results in
HttpWebRequest object throwing an exception. I, however, still need to
access the response stream from the server as it contains information that
I need. Any ideas how I can do that?

Thanks,
Konstantin

try
{
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/myUrl");
myRequest.Method = "GET";
WebResponse response = myRequest.GetResponse();
//If the server returns 5xx status code the next statement executed will
be in the catch block
//Nevertheless, I still need the response stream from the server
Stream responseStream = response.GetResponseStream();
}
catch (System.Exception exc)
{
//Process exception
//How can I access the response stream from here?
}

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
10
by: Brian Brown | last post by:
I have code which works as an asp.net page that posts an xml file to web page and gets a response back. When the the calls GetResponse() it goes into the page it's posting to to and works fine....
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
5
by: japslam japslam via DotNetMonster.com | last post by:
Hi all, I have problem when I use HttpWebRequest and take long time to call to my service server. If at that time there are many request comes in semultaneous, I will get this exception ...
1
by: sfoxover | last post by:
Hi, Could someone please give me some suggestions on how to make this class robust. I need to be able to handle around 20 similtanious requests to this class which causes a web browser to...
6
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." ...
1
by: Kevin Landymore | last post by:
I have a vb.net service running under a Domain account. I'm trying to call a web service on our Mainframe (IBM CICS via SSL and Client Certificates) and after a while (1 or 2 days.. thousands of...
2
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi I have a utility class, called MailHandler, that I wrote to read and operate on emails on an Exchange server using WebDAV. The WebDAV SQL statements are sent using an HttpWebRequest object....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.