Re: problem with HttpWebRequest GetResponse

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



It is possible that the server is actually sending an illegal HTTP response.
This happens with some servers. You can change a configuration setting in
the system.net configuration section (httpWebRequest element) like so, to
allow unsafe header parsing:

<configuration>
<system.net>
<settings>
<httpWebRequest
useUnsafeHeaderParsing="true"
/>
</settings>
</system.net>
</configuration>

It may fix the problem.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:efP%23IiSdGHA.3840@xxxxxxxxxxxxxxxxxxxxxxx
What exactly is in "data"? I know it's in byte array format, but what is
it in string format?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"bg" <bg@xxxxxx> wrote in message
news:O2RGvRSdGHA.3348@xxxxxxxxxxxxxxxxxxxxxxx
Hi all.

I 'm trying to automate some of my workflow, by doing some programmatic
"POST"s to an internal webserver via HttpWebRequest. The Code is your
usual straight forward type of thing.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType="application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream newStream=req.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
reponse = req.GetResponse() as HttpWebResponse; <===goes bang here

But on the GetResponse I get an "The underlying connection was closed:
The server committed an HTTP protocol violation." exception.

Now the thing is if I use the excellent TcpTrace utility to trace whats
going over and coming back I can see that valid data is being retrieved
from the call, So how can I ignore the exception and just get to the
response data? (HaveResponse is true, but response ==null)

Or perhaps there's a flag i'm not setting somewhere?

TIA.

bg






.



Relevant Pages

  • Re: socket error
    ... It ended up with something to do with our Proxy configuration. ... but on the 2.0 box for some reason the httpwebrequest couldnt ... Yes I can visit that page directly through a browser on the server. ... >> | Dim returnstr As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Image upload to one site, save data in another
    ... I decided to have my server act as the proxy and repost the image to the ... HttpWebRequest) ... hosting service, rather than having to route it thru my application. ... server, then parse the response, then do a normal postback. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Debugging web server problems (serving PPP users)
    ... >> The problem I had was with the OSU web server configuration. ... >Apparently, the server cannot detect that the response not only came, ... The timeout is on the basis of whether the response has completed, ...
    (comp.os.vms)
  • RE: Reading the stream from a web response causes timeouts CODE 206
    ... appears that when I request the aforementioned file, the server is returning ... So in my code below, before I get the response, I call ... How to handle code 206's with HttpWebRequest and HttpWebResponse? ...
    (microsoft.public.dotnet.framework)
  • HttpWebRequest exception
    ... While using HttpWebRequest to submit a form, ... An unhandled exception of type 'System.Net.WebException' occurred in ... The server committed a protocol violation. ... response in correct http format. ...
    (microsoft.public.dotnet.languages.csharp)