I'm trying to send a GET request with a token authentication, but i get an unauthorized response. If i send the same request on Postman, it works.
Here's my code :
string url = string.Format("{0}batchs", MyUrl);
RestClient client = new RestClient(url);
RestRequest getRequest = new RestRequest(Method.GET);
getRequest.AddHeader("Accept", "application/json");
getRequest.AddHeader("Authorization", "token " + MyToken);
getRequest.AddParameter("name", MyName, ParameterType.QueryString);
IRestResponse getResponse = client.Execute(getRequest);
And here's my postman request :
Postman request
Any ideas on how to correct this ?
Thanks !
Since RestSharp uses the HttpClient, we should consider similar issues regarding the RestClient instantiation.
RestSharp is a comprehensive, open-source HTTP client library that works with all kinds of DotNet technologies. It can be used to build robust applications by making it easy to interface with public APIs and quickly access data without the complexity of dealing with raw HTTP requests.
RestSharp is a C# library used to build and send API requests, and interpret the responses. It is used as part of the C#Bot API testing framework to build the requests, send them to the server, and interpret the responses so assertions can be made.
I'm not sure exactly what kind of auth you're using, but I use a firebase token generated at runtime, and this is the only thing I could get to work for me.
request.AddHeader("authorization", "Bearer " + _fireBaseService.AuthToken);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With