Click to See Complete Forum and Search --> : How do you post XML via HTTP?
ccrookston
09-25-2006, 09:35 AM
I have what seems like should be a simple questtion, but I can't seem to find the answer.
I have an XML file which I want to post to a remote server. How do I do this? Let's say the URL to which I want to post is:
https://xml.foobar.com/sendrequest
and let's say my xml file is called xmltest.xml
How do I subit the content of xmltest.xml to this remote URL via HTTP? Thanks,
Casey
Stephen Philbin
09-29-2006, 10:10 AM
You mean the contents of a form? Or all the markup of a page? Can you be a lot more specific please?
ccrookston
09-29-2006, 03:52 PM
Hi Stephen (or anyone),
I don't mean the contents of a form. I have a file called ups.xml which contains a complete xml data set. I know that XML file is well formatted and contains all the correct data. I can also load the entire contents of this file into a string. Now I need to send this string to a remote URL. I can't use web services - needs to be an HTTP Post.
Any help would really be great - I have been looking everywhere and can't find anything.
Thanks!!!
chazzy
09-29-2006, 04:02 PM
are you talking about using a web service?
ccrookston
09-29-2006, 04:17 PM
Hi Chazzy,
No. I can't use a web service. This needs to be just a plain old HTTP Post of a string that contains XML.
Any pointers?
NogDog
09-29-2006, 04:21 PM
What server-side programming language/framework are you using? (For instance, if using PHP, you could probably use the cURL extension to post it.)
ccrookston
09-29-2006, 04:27 PM
I should have mentioned I'm using .NET.
NogDog
09-29-2006, 04:29 PM
I should have mentioned I'm using .NET.
OK, I'll move this to that forum, since that's really where the answer will lie.
sirpelidor
09-30-2006, 12:13 AM
the System.Net.WebClient (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebclientclasstopic.asp) class provides methods, allowing you to programmincally upload/download data from a valid URL.
assuming the string of your XML content is stored in a stringBuilder object.
using System.IO;
using System.Net;
//pass the xml content and the address destination as param
//return true when success, false if fail
public bool sendHTTPpost(stringbuilder senderString, string URL){
byte[] postData = Encoding.ASCII.GetBytes(senderString.toString().Trim());
WebClient wClient = new WebClient();
try{
//create stream using http POST
Stream postStream = wClient.OpenWrite(URL,"POST");
//write data
postStream.Write(postData,0,postData.Length);
//release resources
postStream.Close();
return true;
}
catch(){
return false;
}
}//end sendHTTPpost
sometimes you may need to authenticate yourself in
order gain access to the web server. You'll need to make use of
WebRequest class and WebResponse Class. (http://www.c-sharpcorner.com/Internet/WebRequestNResponseMDB.asp) .