Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request is failing when Bearer token is used in .NET #22

Open
imran619 opened this issue Jan 7, 2020 · 1 comment
Open

POST request is failing when Bearer token is used in .NET #22

imran619 opened this issue Jan 7, 2020 · 1 comment

Comments

@imran619
Copy link

imran619 commented Jan 7, 2020

Hi, I'm trying out the POST request with the Bearer token in both Java and .NET. The Java version works fine, but the .NET version is failing. Please find the request and the response below for .NET.

.NET:

Request:
HttpResponse<string> httpResponse = Unirest.post("https://gorest.co.in/public-api/users") .header("Content-Type", "application/json") .header("Accept", "application/json") .header("Authorization", "Bearer Z1UQZlHX3YYchYeqjd1M04ZiHq6XFhfbsKYT") .body(JObject.Parse("{\n \"first_name\": \"Brian\",\n \"last_name\": \"Ratke\",\n \"gender\": \"male\",\n \"email\": \"[email protected]\",\n \"status\": \"active\"\n}")) .asJson<string>();

Response:
{ "_meta": { "success": false, "code": 401, "message": "Authentication failed." }, "result": { "name": "Unauthorized", "message": "Your request was made with invalid credentials.", "code": 0, "status": 401 } }

Java:

Request:
HttpResponse<String> response = Unirest.post("https://gorest.co.in/public-api/users") .header("Content-Type", "application/json") .header("Accept", "application/json") .header("Authorization", "Bearer Z1UQZlHX3YYchYeqjd1M04ZiHq6XFhfbsKYT") .body("{\n \"first_name\": \"Brian\",\n \"last_name\": \"Ratke\",\n \"gender\": \"male\",\n \"email\": \"[email protected]\",\n \"status\": \"active\"\n}") .asString();

Response:
{"_meta":{"success":true,"code":201,"message":"A resource was successfully created in response to a POST request. The Location header contains the URL pointing to the newly created resource.","rateLimit":{"limit":30,"remaining":29,"reset":2}},"result":{"id":"1799","first_name":"Brian","last_name":"Ratke","gender":"male","dob":null,"email":"[email protected]","phone":null,"website":null,"address":null,"status":"active","_links":{"self":{"href":"https://gorest.co.in/public-api/users/1799"},"edit":{"href":"https://gorest.co.in/public-api/users/1799"},"avatar":{"href":null}}}}

Is there any resolution for the issue in .NET? Thanks.

@JoNMii
Copy link

JoNMii commented Mar 12, 2021

Hey @imran619
Im facing same issue trying to use "Cookie" header. Even i add it , it doesnt use it.

I've checked it with Fiddler Proxy, inspecting the request and it is not using the header i've set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants