在使用C#进行多次异步post请求的时候,只有首次发送有请求体,后续发送接收方均检测没有请求体而报错。不知道是什么原因,请教一下大家,使用的标准的post异步请求方式。
具体代码,
private void TwoNetSend(string objectURL, string sendData)
{
string URL = "";
string requestURI = "";
bool bEnable = GetTwoNetParas(out URL, out requestURI);
//bool bEnable = true;
if (bEnable == false)
{
return;
}
try
{
HttpClient _Client = new HttpClient();
_Client.BaseAddress = new Uri(URL);
_Client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
Dictionary<string, string> paras = new Dictionary<string, string>();
paras.Add("URL", objectURL);
paras.Add("sendData", sendData);
string pc = JsonConvert.SerializeObject(paras);
StringContent postContent = new StringContent(pc, Encoding.GetEncoding("GBK"), "application/json");
var response = _Client.PostAsync(requestURI, postContent).Result;
bool result = response.IsSuccessStatusCode;
_Client.Dispose();
}
catch (Exception ex)
{
Noter.Write(ex.ToString(), "TwoNetSend");
return;
}
}