c#:HTTP POST

时间:2017-12-20 09:03:39

标签: c# http post callback

我想知道你能帮我吗?你们中的任何人都知道在HTTP POST上设置回调的方法吗?我可以从POST获得响应没有问题,但这是我正在处理的项目的要求,我应该设置一个回调来接收其他数据。

以下是我所拥有的c#代码的片段:

...

httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);

//Set HttpWebRequest properties
byte[] bytes;
bytes = Encoding.ASCII.GetBytes(xmlString);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = "text/xml; encoding='utf-8'";

//Get stream object
requestStream = httpWebRequest.GetRequestStream();

//Writes a sequence of bytes to the current stream
requestStream.Write(bytes, 0, bytes.Length);

//Close stream
requestStream.Close();

//Sends the HttpWebRequest and wait for its response
httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;

if (httpWebResponse.StatusCode == HttpStatusCode.OK)
{
    //Get response stream
    responseStream = httpWebResponse.GetResponseStream();

   //Obviously from here we can get the response etc..      
}

//Close HttpWebResponse, 
httpWebResponse.Close();

...

任何帮助将不胜感激!

0 个答案:

没有答案