我正在使用 HttpClient
进行一个简单的调用。问题在于它似乎没有发送我提供的内容。服务器因此向我返回了一个错误,当我使用 Fiddler 查看请求时,它并未像应该展示出内容:
HttpContent content = new FormUrlEncodedContent(
new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key1", "value1"),
new KeyValuePair<string,string>("key2","value2"),
new KeyValuePair<string,string>("key3","value3"),
new KeyValuePair<string,string>("key4", "value4"),
new KeyValuePair<string, string>("key5", "value5"),
new KeyValuePair<string, string>("key6", "value6")
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
content.Headers.ContentType.CharSet = "UTF-8";
HttpResponseMessage resposne = await client.PostAsync(new Uri("my_url"), content);
有什么建议可能出了问题吗?
ContentType
属性不是字符串类型,因此您无法将其分配给字符串值。因此,这甚至无法编译。 - Darin Dimitrov