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