我正在尝试使用HttpClient通过uri制作一个http帖子,如下所示。
var request = new Dictionary<string, string>();
request.Add("FirstName", "Sibi");
var requestData= new FormUrlEncodedContent(request);
var httpClient= new HttpClient(new HttpClientHandler
{
AllowAutoRedirect = true,
Credentials = new NetworkCredential
{
UserName = settings.Username,
Password = settings.Password
},
CookieContainer = new CookieContainer(),
});
// Set the base address
httpClient.BaseAddress = new Uri(settings.Url);
var req = new HttpRequestMessage(HttpMethod.Post, uri)
{
Content = requestData
};
var httpResponse = await httpClient.SendAsync(req);
但不知何故,目标网址请求是通过Body进行的。我检查了小提琴手,它看起来像下面
POST http://localhost:65518/api/Employee/Create HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Connection: Keep-Alive
Content-Length: 45
Host: localhost:65518
FirstName=Sibi&LastName=P.G&Age=23&Salary=100
我不知道为什么不通过Uri。任何帮助将非常感激。我试图点击本地URL(在VS 2015中运行IIS Express)。我在.net core 1.0.1