簡體   English   中英

如何在 httpClient 中發布參數,在 postman 中使用參數

[英]How can I Post parameter in httpClient where in postman use param

我想用 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的格式應該是什么?

使用此代碼:

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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM