469,328 Members | 1,266 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Using HTTP request to POST XML files?

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
3 11067


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
Many thanks - looks like it's what I needed. I'll give it a try.

Thanks again

Paul

Nov 12 '05 #3
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.

Similar topics

reply views Thread by Pieter Edelman | last post: by
2 posts views Thread by parseint | last post: by
1 post views Thread by Asha | last post: by
3 posts views Thread by darin dimitrov | last post: by
7 posts views Thread by Mark Waser | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.