[英]restsharp get error (authentication)
I have a API GET call that works in postman BUT not in VS2017. 我有一个API GET调用,但在VS2017中无法在邮递员中使用。 I copied the code from postman:
我复制了邮递员的代码:
var client = new RestClient("http://server- d01:9000/amp/portal/api/dougtest/v1");
var request = new RestRequest(Method.GET);
request.AddHeader("Postman-Token", "19763da3-4b00-4e92-83e0-1ac75f99d219");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("X-XSRF-TOKEN", "71cf12361-8090-499a-adc3-2d5e98a04143");
request.AddParameter("undefined", "{\n \"username\":\"domain\\\\username\",\n \"password\":\"myPasswd\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
The error I am getting is unauthorized, the API required a header of X-XSRF-TOKEN
with a value of 71cf12361-8090-499a-adc3-2d5e98a04143
(a fake key) 我得到的错误是未经授权的,API需要
X-XSRF-TOKEN
的标头,其值为71cf12361-8090-499a-adc3-2d5e98a04143
(假密钥)
Using postman, everything works just fine, but using VS2017 I get an error: 使用邮递员,一切都很好,但是使用VS2017我得到一个错误:
{"status":"unauthorized","error":"Login is required","errormsg":null}
What's weird (I am new to this so pardon my ignorance)is that the header does not contain: 奇怪的是(我对此很陌生,请原谅我的无知)是标题不包含:
request.AddHeader("X-XSRF-TOKEN", "71cf12361-8090-499a-adc3-2d5e98a04143");
but rather the parameter does, which is confusing since I thought the AddHeader
would add it to the header but maybe I am misunderstanding something.... 但是参数确实可以,这很令人困惑,因为我以为
AddHeader
会将其添加到标题中,但也许我误会了...。
any advice/suggestions would be extremely welcomed 任何建议/建议都将受到欢迎
thank you in advance 先感谢您
dougc 道格
Please use the below code and check 请使用下面的代码并检查
var client = new RestClient("http://server- d01:9000/amp/portal/api/dougtest/v1");
var request = new RestRequest(Method.GET);
//Make sure to give the Valid Token
request.AddHeader("Authorization","X-XSRF-TOKEN <<Generated Token>>");
IRestResponse response = client.Execute(request);
Console.WriteLine("Response :" + response.Content);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.