简体   繁体   English

请求来自 Postman 但不是来自 c# 代码

[英]Request works from Postman but not from c# code

Whenever I am adding an HTTP body into my Http Request I am getting a 401 response code.每当我将 HTTP 正文添加到我的 Http 请求中时,我都会收到 401 响应代码。 The same request is working postman perfectly fine.同样的请求在 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);

Get the code snippet from postman and copy the cookie header line.i hope it works for you从 postman 获取代码片段并复制 cookie header 行。我希望它对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM