如何调用不等待响应的Web API端点

时间:2017-04-27 08:10:48

标签: asp.net-web-api asp.net-web-api2

我们正在从组件调用Web API端点(EP),我们不希望组件等到它从End Point获得响应。 我们使用下面的代码调用End Point,下面的代码正在等待End Point的响应。

有人可以提供一些见解来实现这一目标。 提前谢谢。

var webAddr = "EndPointURL";

var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);

httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = 0;
httpWebRequest.KeepAlive = false;
httpWebRequest.Timeout = System.Threading.Timeout.Infinite;
httpWebRequest.Headers.Add("Authorization", Token);
httpWebRequest.Headers.Add("BatchId", 25);
httpWebRequest.Headers.Add("UserName", "ABC");

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();   

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
}

1 个答案:

答案 0 :(得分:0)

    ## FOLDER 01 > FILE 01.md, here data in file like hk as heading (for Heading you can put # before hk)and hv
    ## FOLDER 02 > FILE 01.md, here data in file like hk as heading (for Heading you can put # before hk)and hv