Re: Using HttpWebRequest and HttpWebResponse



Thanks for all the responses... not.

I got around this by wrapping the HttpWebRequest.GetResponse call in a
Try-Catch block and catching the System.Net.WebException that gets thrown
when an HTTP 4xx or 5xx status is returned. Then I set my HttpWebResponse
variable to WebException.Response - the original response. If you don't
catch and handle this exception, GetResponse returns an HTTP 500 response
with content that says "The remote server returned xxx" where xxx is the 4xx
or 5xx code of the original response - but in this case you've lost the
content that went with that response. By catching the exception I was able
to get the original response with its content that included XML I needed.

Zoe

"Zoe Hart" <zoe.hart@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OCu0Z0MmIHA.4208@xxxxxxxxxxxxxxxxxxxxxxx
I maintaining or trying to maintain a relatively simply HttpHandler. The
idea is that it takes a request to http://myhandler/url/someURL and creates
a request to http://someaddress/someresource. When it gets the response, it
streams that response back to the original incoming request. So it's
basically just mapping url/someURL to someaddress/someresource, with the
mapping information being supplied in the handler's config file.
Within the HttpHandler code, we're using HttpWebRequest to create the
internal request to the mapped resource and HttpWebResponse to capture the
response that we then stream back as the response to the original request.
This works well when the HttpWebRequest generates an HTTP 200 response.
When the generated HttpWebRequest results in an Http 4xx or 5xx, instead
of getting the actual response streamed back to the original request, I'm
getting an HTTP 500 with the message "The remote server returned an error:
(xxx)" where xxx is the HTTP status code of the response to the internally
generated request. I assume that either HttpWebRequest or HttpWebResponse
is doing this wrapping of the original response. How can I get the actual
response code and content to the internally generated request streamed
back to the original request instead of this wrapper.

Thanks,
Zoe



.



Relevant Pages

  • Re: Little problem with C program
    ... 'sizeof request' returns the size of a pointer, ... you need to do with HTTP.) ... > message "Reading response ..." ... That system puts the GET inside the function, so I call it like this: ...
    (comp.programming)
  • Re: Screen Scraping a Password Protected Site
    ... http traffic. ... cookies to a singleton CookieContainer and the once you have logged in ... If TypeOf request Is HttpWebRequest Then ... If TypeOf response Is HttpWebResponse Then ...
    (microsoft.public.dotnet.languages.vb)
  • Fwd: Hello
    ... response = meth ... raise HTTPError, code, msg, hdrs, fp) ... But now when I use this http request ...
    (comp.lang.python)
  • Re: HTTP question
    ... > then before I receive any response back from the server I issue another GET ... > request for a different web page. ... Will I get an error back from the server? ... HTTP client waits for the first response before sending the second ...
    (comp.infosystems.www.servers.misc)
  • Re: W2K3 IIS 6.0 ASP.NET Requests Per Second Limits?
    ... allow the page to tell ASP.Net "don't send a response yet until I tell ... this request is "leaked" and will never ... It is when the callback executes with both the async function call ... The thread executing code literally calls into Function1, execute code, ...
    (microsoft.public.inetserver.iis)