var client = new HttpClient();
var request = new HttpRequestMessage();
request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var requestData = new Dictionary<string, string>
{
{ "FirstName", user.FirstName},
{ "LastName", user.LastName },
{ "Date_Of_Birth", user.Date_Of_Birth.ToString()},
{ "Gender", user.Gender},
{ "Status", user.Status.ToString()}
};
request = new HttpRequestMessage()
{
RequestUri = new Uri("https://localhost:7169/api/User/Add"),
Method = HttpMethod.Post,
Content = new FormUrlEncodedContent(requestData)
};
var response = client.PostAsync(request.RequestUri,request.Content);
我当前的代码不起作用?
1条答案
按热度按时间myzjeezk1#
也许您可以将此代码简化为: