BuddyWork wrote:
Hello,
I want to send a XML message (string) to an ASP.net page,
I don't want to use WebService because the ASP.net page
has been developed by an external company, can you please
point me to the correct location for examples on how to
send XML messages to an ASP.net page using C#.
Here's a sample method:
public void PostXml(string url, string xml) {
byte[] bytes = Encoding.UTF8.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);
}
}
}
You may want to adjust encoding and content type according to your
requirements.
Cheers,
--
Joerg Jooss
jo*********@gmx.net