POST request is failing when Bearer token is used in .NET
Opened this issue · 1 comments
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\": \"lew3000@roberts.com\",\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\": \"lew2011@roberts.com\",\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":"lew2011@roberts.com","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.