473,396 Members | 1,814 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,396 software developers and data experts.

problem with HttpWebRequest GetResponse

bg
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
May 11 '06 #1
5 2362
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@bg.com> wrote in message
news:O2**************@TK2MSFTNGP03.phx.gbl...
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

May 11 '06 #2
On 2006-05-11 19:27:16 +0100, "Kevin Spencer"
<ke***@DIESPAMMERSDIEtakempis.com> said:
What exactly is in "data"? I know it's in byte array format, but what
is it in string format?


its the name/value pairing stuff thats normally supplied by the form,

property1=value&property2=value.....

I took the data straight from a trace I had and still got the same exception.
May 11 '06 #3
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" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ef****************@TK2MSFTNGP04.phx.gbl...
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@bg.com> wrote in message
news:O2**************@TK2MSFTNGP03.phx.gbl...
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


May 11 '06 #4
Thus wrote BG,
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)


Can you post a sample HTTP response? My usual answer is "fix the broken server"
;-)

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
May 12 '06 #5
bg
Added "useUnsafeHeaderParsing="true"" to my app.config and it now works a
treat - thanks Kevin
May 12 '06 #6

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

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
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 ...
3
by: Taner Özyürekoglu | last post by:
I have an error below. is there any idea about it. Dim Req As HttpWebRequest = WebRequest.Create("https://certification.authorize.net/gateway/transact.dll?" & postdata) Response.Write("3")...
2
by: GlennLanier | last post by:
Hello, I've searched the forums and can't find an answer -- if it i there, kindly point me in that direction. I would like to simulate a browser POSTing a FORM and be able to pars the response....
0
by: Veerle | last post by:
Hi, On the website of the Belgian lottery, you can download an excel sheet with lottery results (the winning numbers) over the years and an excel sheet with financial results (the winnings) over...
1
by: bliz_87 | last post by:
Hello all, I'm trying to create a simple application that does a HTTP request/response on a button click. Here's the entire code which I got from a reference book: using...
6
by: Georg | last post by:
Hello, I am trying to load a web page over a HTTP proxy with the POST method and I am using the following code: // open request (string url) HttpWebRequest httpWebRequest =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.