我想用 HttpClient 發布我的引數。httpclient 請求正文中的內容是什么?我把它寫在正文部分,當我運行專案時,我得到了錯誤。
我的代碼是:
string baseAddress = "https://WebServiceAddress";
Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
HttpRequestMessage bodyRequest = new HttpRequestMessage(HttpMethod.Post, baseAddress)
bodyRequest.Content = new StringContent(JsonConvert.SerializeObject(Prescriptionrequest), Encoding.UTF8, "application/json");
var responseApi = Client.PostAsync(baseAddress, bodyRequest.Content, new System.Threading.CancellationToken(false));
應該是什么格式bodyRequest.Content?
uj5u.com熱心網友回復:
使用此代碼:
HttpClient client = new HttpClient();
var dictionary = new Dictionary<string, string>
{
{ "parameter0", "value0" },
{ "parameter1", "value1" }
};
var content = new FormUrlEncodedContent(dictionary);
var response = await client.PostAsync("https://WebServiceAddress", content);
var responseString = await response.Content.ReadAsStringAsync();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/430759.html
標籤:C# api 网页服务 httpclient
