请求可从Postman发出,但不能从C#代码发出

ogq8wdun  于 2022-12-13  发布在  Postman
关注(0)|答案(1)|浏览(205)

每当我在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);
yc0p9oo0

yc0p9oo01#

从postman获取代码片段并复制cookie标题行。希望它对您有用。

相关问题