Hi,
I've been struggling with this POST problem for more than three hours
now, and don't see any light.
Below is the troublesome code snippet:
System.Net.HttpWebRequest req =
HttpWebRequest)System.Net.WebRequest.Create(URI);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.Method="POST";
req.SendChunked=true;
req.ContentType = @"application/x-www-form-urlencoded";
req.ContentLength = bytes.Length;
req.Headers.Add("Accept-Encoding: gzip, deflate");
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
Console.WriteLine("The value of 'ContentLength' property after sending
the data is {0}", req.ContentLength);
os.Close();
Now, when I send the request:
System.Net.HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
it gives me an exception: 411 Length required.
I know this means that the Content-Length header needs to be set. the
WriteLine gives me a valid number, 561, and checking with Fiddler2
shows no Content-Length header. In fact, checking req.Headers.AllKeys
shows no Content-Length header, even after I set it.
I cannot even do:
req.Headers.Add("Content-Length: " + bytes.Length.ToString());
because it throws an ArgumentException saying that this header should
be set by the appropriate property.
What is going on completely escapes me!
Any help much appreciated!
Rana 1 2450
Hi Rana,
Try amending your code to the following
os.Write(bytes, 0, bytes.Length);
os.Flush();
Still having problems let me know.
Steve
<wo*******@hotmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
Hi,
I've been struggling with this POST problem for more than three hours
now, and don't see any light.
Below is the troublesome code snippet:
System.Net.HttpWebRequest req =
HttpWebRequest)System.Net.WebRequest.Create(URI);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.Method="POST";
req.SendChunked=true;
req.ContentType = @"application/x-www-form-urlencoded";
req.ContentLength = bytes.Length;
req.Headers.Add("Accept-Encoding: gzip, deflate");
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
Console.WriteLine("The value of 'ContentLength' property after sending
the data is {0}", req.ContentLength);
os.Close();
Now, when I send the request:
System.Net.HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
it gives me an exception: 411 Length required.
I know this means that the Content-Length header needs to be set. the
WriteLine gives me a valid number, 561, and checking with Fiddler2
shows no Content-Length header. In fact, checking req.Headers.AllKeys
shows no Content-Length header, even after I set it.
I cannot even do:
req.Headers.Add("Content-Length: " + bytes.Length.ToString());
because it throws an ArgumentException saying that this header should
be set by the appropriate property.
What is going on completely escapes me!
Any help much appreciated!
Rana This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James |
last post by:
Hi
I am having some trouble getting a asp page to load. Im a
noob to the asp side. I have followed knowledege base
Article 301305. I am running 2000 adv, IIS 5.0
I have the following...
|
by: Jacek Dziedzic |
last post by:
Hi!
First of all, I hope my problem is not too loosely tied to the
"standard C++" that is the topic of this group.
I have some code that exhibits a strange behaviour: on
one computer, where I...
|
by: |
last post by:
In .NetCF, upon trying to access the following URL:
http://rss.news.yahoo.com/rss/business
via the following code:
WebRequest webReq = WebRequest.Create(url);
WebResponse webResp =...
|
by: Jim Bancroft |
last post by:
Hi everyone,
I'm running into a problem with my ASP.Net application. I've just created a
new aspx page which uses some new components of mine that inherit from
ServicedComponent and are...
|
by: Daniel Walzenbach |
last post by:
Hi,
I have a web application which sometimes throws an “out of memory”
exception. To get an idea what happens I traced some values using performance
monitor and got the following values (for...
|
by: Olivier BESSON |
last post by:
Hello,
I have a web service of my own on a server (vb.net). I must declare it with
SoapRpcMethod to be used with JAVA.
This is a simple exemple method of my vb source :
...
|
by: nakul.reddy |
last post by:
I'm trying to use HTTPWebRequest to POST data to a website using
multipart/form-data.
It's HTTPS, and it returns a response object with -1 ContentLength.
Any help would be appreciated!
Below...
|
by: JLupear |
last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post?
I split it...
|
by: mrchatgroup |
last post by:
news from
http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html
Small Accidents Mean Big Trouble for Supercollider
Image
Scientists expect startup...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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 projectplanning, coding, testing,...
| |