0%

ASP.NET Core C# Post Form Data

ASP.NET Core 要怎麼 Post Form Data using HttpClient

這樣就可以
StackOverflow: How to post data using HttpClient?

1
2
3
4
5
6
7
8
9
10
11
12
var comment = "hello world";
var questionId = 1;

var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("comment", comment),
new KeyValuePair<string, string>("questionId", questionId)
});

var myHttpClient = new HttpClient();
var response = await myHttpClient.PostAsync(uri.ToString(), formContent);

And if you need to get the response after post, you should use:

1
var stringContent = await response.Content.ReadAsStringAsync();