[英]httpClient.PostAsync(url, content) not working in C# Metro apps
I am using HttpClient.PostAsync()
method to send post request to my web service api. 我正在使用HttpClient.PostAsync()
方法将发布请求发送到我的Web服务api。 I am passing api URL address along with queryString parameters in it.. but PostAsync()
method is not working correctly, giving an error : 我正在传递api URL地址以及其中的queryString参数。.但是PostAsync()
方法无法正常工作,并给出错误消息:
Status Code 417 expectation failed. 状态码417预期失败。
public override async void SendPostRequest(REQUEST_NAME reqName, IDictionary<string, object> args)
{
var _client = new System.Net.Http.HttpClient();
_client.BaseAddress = new Uri("http://www.example.com/api/v2.0/");
_client.MaxResponseContentBufferSize = 256000;
string queryString = "?";
string url = reqName.ToString() + ".json" + queryString;
string queryStringparam = "";
foreach (KeyValuePair<string, object> param in args)
{
queryStringparam += param.Key + "=" + param.Value + "&";
}
// queryStringparam=name="abc&age=25&event=browsed&url=www.google.com"
var response = await _client.PostAsync(url, new StringContent(queryStringparam));
if (response.IsSuccessStatusCode)
{
}
May be I am passing parameters in wrong way in PostAsync()
method. 可能是我在PostAsync()
方法中以错误的方式传递了参数。 Please give me your suggestion about it. 请给我您的建议。 Thanks. 谢谢。
According to this MSDN forum thread , this can be caused by proxies that don't support the "100 continue" expectation. 根据此MSDN论坛主题 ,这可能是由不支持“继续100个”期望的代理引起的。
As a workaround, set ServicePointManager.Expect100Continue
or HttpRequestHeaders.ExpectContinue
to false
. 解决方法是,将ServicePointManager.Expect100Continue
或HttpRequestHeaders.ExpectContinue
设置为false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.