我已经编码了想要传递的数据,就像String传递给HttpClient PostRequest一样
但FormUrlEncodedContent仅接受dictonary作为参数
我想要像client.PostAsync(url,plain_string_content)
这样的东西 var content = new FormUrlEncodedContent(values);
using (var client = new HttpClient())
{
try
{
var response = client.PostAsync(url, content).GetAwaiter().GetResult();
string resp=response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
return resp;
}
答案 0 :(得分:1)
您可以使用HttpClient.SendAsync
:
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post);
request.Content = new StringContent(plain_string_content);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
await client.SendAsync(request);
请注意,毕竟PostAsync
和其他HttpClient
方法是SendAsync
的快捷方式。