.Net如何将内容类型设置为application / x-www-form-urlencoded with HttpClient for GetAsync Request

时间:2017-06-21 13:19:27

标签: c# asp.net-web-api dotnet-httpclient

有谁知道如何设置GET异步请求的内容类型? 我尝试发送API的GET异步请求,但无法确定如何将内容类型设置为" application / x-www-form-urlencoded"。

这是邮递员的定义:Encode GET request 这是Postman的结果:202 response

static HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://api.domain.com/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/location/trackInfo?" + filter.URLQuery);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
    trackInfo = await response.Content.ReadAsAsync<List<TrackingInformation>>();
}

0 个答案:

没有答案