Tom wrote:
Hi.
After I got some information from the user
I need to POST it in XML format to the server
NOT MY SERVER - a server at https://xxxx.xxx
and to reveive the response.
Please let me know how to do it.
THANKS !!!!!
Here's some sample code that should get you started:
public void PostXml(string url, string xml, Encoding encoding) {
byte[] bytes = encoding.GetBytes(xml);
PostBinary(url, bytes, "text/xml");
}
public void PostBinary(string url, byte[] bytes, string contentType) {
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = contentType;
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);
}
}
}
Cheers,
--
Joerg Jooss
www.joergjooss.de ne**@joergjooss.de