sushi wrote:
But how to send data through the HttpWebRequest class object. I am
using HttpWebRequest class so as to send an HTTP Post request.
Write your data to the request stream.
Here's a sample method that allows you post any kind of binary contents:
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);
}
}
}
Assuming you have an XML string "xml", a target URL "url", and you want
to use UTF-8 encoding, all you need to do is
byte[] bytes = Encoding.UTF8.GetBytes(xml);
PostBinary(url, bytes, "text/xml");
Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de