473,396 Members | 2,030 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.

HTTP Post Question

Hi,

I am trying to to create a HTTP Request that posts XML that mimics the html
form below.

<form name="Form1" method="post" action="http://test/xml.aspx" id="Form1">
<textarea name="OrderXml" id="OrderXml"
style="height:342px;width:550px;Z-INDEX: 104; LEFT: 65px; POSITION:
absolute; TOP: 84px" rows="1" cols="20"></textarea>
<p>
<input type=submit name='Submit Order' value='Submit Order'>
</form>

I can get the code below to work. Any ideas?

HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(http://test/xml.aspx);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(httpRequest.GetRequestStream(),
System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
//.. Write XML
xmlWriter.WriteEndDocument();
xmlWriter.Close();
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
//.. store XML

Sep 24 '06 #1
3 1769
Thus wrote Matt,
Hi,

I am trying to to create a HTTP Request that posts XML that mimics the
html form below.

<form name="Form1" method="post" action="http://test/xml.aspx"
id="Form1">
<textarea name="OrderXml" id="OrderXml"
style="height:342px;width:550px;Z-INDEX: 104; LEFT: 65px; POSITION:
absolute; TOP: 84px" rows="1" cols="20"></textarea>
<p>
<input type=submit name='Submit Order' value='Submit Order'>
</form>
I can get the code below to work. Any ideas?

HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(http://test/xml.aspx);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
XmlTextWriter xmlWriter = new
XmlTextWriter(httpRequest.GetRequestStream(),
System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
//.. Write XML
xmlWriter.WriteEndDocument();
xmlWriter.Close();
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
//.. store XML

Your code does something rather different from what the HTML form does.

The HTML form will send a HTTP message body like this:
OrderXml=<contentOfOrderXml>&Submit+Order=Submit+O rder

Your code posts a raw XML document in the HTTP message body:
<?xml version="1.0" ?><foo><bar>xyz</bar></foo>

Also note that Content-Type for an HTML form is application/x-www-form-urlencoded,
not text/xml.

Therefore
- change your Content-Type
- make sure to write URL encoded key/value pairs to the request stream, with
the keys being the form field names and the values being the form field values

Note that WebClient.UploadValues() already implements all of the above ;-)

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Sep 27 '06 #2
I appreciate the response. I had a few questions:

1) How can I get NameValueCollection for WebClient.UploadValues() represent
a tiered xml document?
2) I did not follow what you mean by: make sure to write URL encoded
key/value pairs to the request stream, with
the keys being the form field names and the values being the form field
values Can you explain this?

Thanks

"Joerg Jooss" <ne********@joergjooss.dewrote in message
news:b1**************************@msnews.microsoft .com...
Thus wrote Matt,
>Hi,

I am trying to to create a HTTP Request that posts XML that mimics the
html form below.

<form name="Form1" method="post" action="http://test/xml.aspx"
id="Form1">
<textarea name="OrderXml" id="OrderXml"
style="height:342px;width:550px;Z-INDEX: 104; LEFT: 65px; POSITION:
absolute; TOP: 84px" rows="1" cols="20"></textarea>
<p>
<input type=submit name='Submit Order' value='Submit Order'>
</form>
I can get the code below to work. Any ideas?

HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(http://test/xml.aspx);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
XmlTextWriter xmlWriter = new
XmlTextWriter(httpRequest.GetRequestStream(),
System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
//.. Write XML
xmlWriter.WriteEndDocument();
xmlWriter.Close();
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
//.. store XML


Your code does something rather different from what the HTML form does.
The HTML form will send a HTTP message body like this:
OrderXml=<contentOfOrderXml>&Submit+Order=Submit+O rder

Your code posts a raw XML document in the HTTP message body:
<?xml version="1.0" ?><foo><bar>xyz</bar></foo>

Also note that Content-Type for an HTML form is
application/x-www-form-urlencoded, not text/xml.

Therefore
- change your Content-Type
- make sure to write URL encoded key/value pairs to the request stream,
with the keys being the form field names and the values being the form
field values

Note that WebClient.UploadValues() already implements all of the above ;-)

Cheers,
--
Joerg Jooss
ne********@joergjooss.de


Sep 27 '06 #3
Disregard my last post I figured it out. I just add the xml string as in
NameValueCollection with a key "OrderXML". It works great and thanks for
the help.

"Matt" <no*****@spam.comwrote in message
news:uO**************@TK2MSFTNGP05.phx.gbl...
>I appreciate the response. I had a few questions:

1) How can I get NameValueCollection for WebClient.UploadValues()
represent a tiered xml document?
2) I did not follow what you mean by: make sure to write URL encoded
key/value pairs to the request stream, with
the keys being the form field names and the values being the form field
values Can you explain this?

Thanks

"Joerg Jooss" <ne********@joergjooss.dewrote in message
news:b1**************************@msnews.microsoft .com...
>Thus wrote Matt,
>>Hi,

I am trying to to create a HTTP Request that posts XML that mimics the
html form below.

<form name="Form1" method="post" action="http://test/xml.aspx"
id="Form1">
<textarea name="OrderXml" id="OrderXml"
style="height:342px;width:550px;Z-INDEX: 104; LEFT: 65px; POSITION:
absolute; TOP: 84px" rows="1" cols="20"></textarea>
<p>
<input type=submit name='Submit Order' value='Submit Order'>
</form>
I can get the code below to work. Any ideas?

HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create(http://test/xml.aspx);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
XmlTextWriter xmlWriter = new
XmlTextWriter(httpRequest.GetRequestStream(),
System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
//.. Write XML
xmlWriter.WriteEndDocument();
xmlWriter.Close();
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
//.. store XML


Your code does something rather different from what the HTML form does.
The HTML form will send a HTTP message body like this:
OrderXml=<contentOfOrderXml>&Submit+Order=Submit+ Order

Your code posts a raw XML document in the HTTP message body:
<?xml version="1.0" ?><foo><bar>xyz</bar></foo>

Also note that Content-Type for an HTML form is
application/x-www-form-urlencoded, not text/xml.

Therefore
- change your Content-Type
- make sure to write URL encoded key/value pairs to the request stream,
with the keys being the form field names and the values being the form
field values

Note that WebClient.UploadValues() already implements all of the above
;-)

Cheers,
--
Joerg Jooss
ne********@joergjooss.de



Sep 27 '06 #4

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

Similar topics

4
by: Gary Petersen | last post by:
For the benefit of others, I want to show how to do an HTTP POST request using fsockopen(). I banged my head against a wall for two days trying to figure this out. I even went to http://php.net/...
10
by: Dave Smithz | last post by:
Hi there, I have a situation where I want to have multiple submit buttons on the same form and therefore want to use a redirection php script that checks the value associated with the submit...
16
by: Andy Lai | last post by:
Hi, I am writing a C++ program which needs to post an XML to an HTTP server periodically and the program will run on different platforms including w32, linux, and unix. I see that there are...
2
by: Steve Lloyd | last post by:
Hi, This is bit of an open question and is more of a theoretical one that an actual coding question but would appreciate some pointers I want to send some data to an external server that will...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
1
by: David | last post by:
I need to redirect to a page and HTTP Post data. The Response.Redirect does not work and the HTTPREQUEST option calls the page and waits for a response, but I need to transfer control to the...
0
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These...
4
by: Bob Bedford | last post by:
Hi all, I'm trying to submit the google sitemap after it has been created on my server with PHP. Here is the code: <?php $address= urlencode('www.mysite.com/sitemap.gz');?> <form...
10
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.......
2
by: =?Utf-8?B?U2Fs?= | last post by:
<I MOVED THIS POST TO ITS OWN THREAD. ORIGINAL POST FOUND HERE:...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
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,...
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...

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.