![](/img/trans.png)
[英]GET request with basic auth works from Postman but not from C#
[英]Request works from Postman but not from c# code
每當我將 HTTP 正文添加到我的 Http 請求中時,我都會收到 401 響應代碼。 同樣的請求在 postman 上運行得很好。
var client = new RestClient("http://10.10.2.10:9000/haproxy_stats");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic QURNSU46UGFzc3dvcmQtMTIzNA==");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("s", "server2");
request.AddParameter("action", "ready");
request.AddParameter("b", "#2");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
從 postman 獲取代碼片段並復制 cookie header 行。我希望它對你有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.