By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,703 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,703 IT Pros & Developers. It's quick & easy.

Using HTTP request to POST XML files?

P: n/a
Hi
Sorry if this is posted in the wrong group but I'm brand new to this
area. Basically I've got to post some XML documents to an external
server using HTTP web request (POST, not GET) and be able to receive
files back. I've got the XML file generated and checked over, but I
just dont know how to go about the post process. I've got a feeling I'm
supposed to create a form in my ASP application with an action which
points at the URL I've got for the external server, but I don't know
how to "attach" the XML files I'm sending. Do I need to embed the files
in the form or do I "point" the form at the files or what?

If anyone could give me some pointers to get me started I'd really
appreciate it. Any sample code would also be gratefully received :-)

Thanks

Paul

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Paul M wrote:
Basically I've got to post some XML documents to an external
server using HTTP web request (POST, not GET) and be able to receive
files back. I've got the XML file generated and checked over, but I
just dont know how to go about the post process. I've got a feeling I'm
supposed to create a form in my ASP application with an action which
points at the URL I've got for the external server, but I don't know
how to "attach" the XML files I'm sending.


Are you using classic ASP or ASP.NET?
With classic ASP you use MSXML e.g.
Set XmlDocument = Server.CreateObject("Msxml2.DOMDocument.4.0")
XmlDocument.async = False
XmlDocument.load Server.MapPath("file.xml")
Set HttpRequest = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
HttpRequest.open "POST", "http://example.com/dir/whatever.jsp", False
HttpRequest.send XmlDocument
With .NET you have more generic objects so some more coding is
necessary, look into WebRequest/HttpWebRequest.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

P: n/a
Many thanks - looks like it's what I needed. I'll give it a try.

Thanks again

Paul

Nov 12 '05 #3

P: n/a
Paul M wrote:
Hi
Sorry if this is posted in the wrong group but I'm brand new to this
area. Basically I've got to post some XML documents to an external
server using HTTP web request (POST, not GET) and be able to receive
files back. I've got the XML file generated and checked over, but I
just dont know how to go about the post process. I've got a feeling
I'm supposed to create a form in my ASP application with an action
which points at the URL I've got for the external server, but I don't
know how to "attach" the XML files I'm sending. Do I need to embed
the files in the form or do I "point" the form at the files or what?

If anyone could give me some pointers to get me started I'd really
appreciate it. Any sample code would also be gratefully received :-)


This is a sample method that illustrates how to use
Syetem.Net.HttpWebRequest/Response to post XML:

public void PostXml(string url, string xml, Encoding enc)
{
byte[] bytes = enc.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}

using (HttpWebResponse response =
(HttpWebResponse) request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK)
{
string message = String.Format(
"POST failed. Received HTTP {0}",
response.StatusCode);
throw new ApplicationException(message);
}
}
}

Actually, this method posts an arbitrary string encoded with an
arbitrary encoding-- the only thing that makes it XML specific is the
Content-Type text/xml.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.