我正在努力让它工作,但它似乎做了意想不到的事情,怎么了?
string xmlToSend = "<elementOne xmlns=\"htt..mynamespace\">.......</elementOne>";
request = (HttpWebRequest)WebRequest.Create(address);
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.Headers["Content-Length"] = xmlToSend.Length.ToString();
_postData.Append(string.Format("{0}", xmlToSend));
request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
....}
和 BeginGetRequestString:
void RequestReady(IAsyncResult asyncResult)
{
HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
Debug.WriteLine("xml" + _postData.ToString());
using (Stream stream = request.EndGetRequestStream(asyncResult))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(_postData.ToString());
writer.Flush();
}
}
request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
}
我想要实现的是将请求的 HTTPBODY 设置为 XML,就像在 iOS (setHTTPBody) 中一样……这是正确的方法吗?