C# 如何在c中设置http post请求的正文#
一个c#和客户机服务器的新手,希望这不是愚蠢的,但我无法理解如何设置http post请求的主体 我必须使用以下对象来发出请求,我不知道如何将请求主体设置为我必须发送的内容C# 如何在c中设置http post请求的正文#,c#,http,C#,Http,一个c#和客户机服务器的新手,希望这不是愚蠢的,但我无法理解如何设置http post请求的主体 我必须使用以下对象来发出请求,我不知道如何将请求主体设置为我必须发送的内容 var request = new HttpRequestMessage(HttpMethod.Post, requestURI); // // Here I believe that I am suppose to set the post request body // var response = httpClient
var request = new HttpRequestMessage(HttpMethod.Post, requestURI);
//
// Here I believe that I am suppose to set the post request body
//
var response = httpClient.SendAsync(request).Result;
谢谢。非常感谢任何帮助 要设置正文,您需要使用
.PostAsync
。GET请求没有正文。您可以使用如下内容:
string xml = String.Empty;
// ... Fill in xml with your data
NameValueCollection parameters = new NameValueCollection();
parameters.Add("data", xml);
byte[] response = null;
string result = String.Empty;
using (WebClient client = new WebClient())
{
response = client.UploadValues(url, parameters);
result = Encoding.ASCII.GetString(response);
}
这是一个post请求,那么为什么不使用
.post
方法呢?