I am using retrofit on newsApi. I am trying to hit endpoint
https://newsapi.org/v2/sources?apiKey=xxxxx
In case of wrong api key server is returning:
{"status":"error","code":"apiKeyInvalid","message":"Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key."}
and in case of no api key server is returning:
{“status”:“error”,“code”:“apiKeyMissing”,“message”:“Your API key is missing. Append this to the URL with the apiKey param, or use the x-api-key HTTP header.”}
but in my application retrofit is returning following for both the cases:
Response{protocol=http/1.1, code=401, message=Unauthorized, url=https://newsapi.org/v2/sources}
just the url is changed for both cases but message and code is same.
Why is retrofit modifying server response and how can I get the original server message or response?
Thanks in advance.
Not having an api key makes you unauthorized, so Retrofit is not wrong to access the error body check out this previous answer
Related
When I use this api to get access token:
https://oauth-login.cloud.huawei.com/oauth2/v3/token?grant_type=client_credentials&client_id=****&client_secret=****
it always returns
{
"sub_error": 20001,
"error_description": "missing required parameter: client_id",
"error": 1102
}
although I send client_id parameter
To solve the issue, Please make sure the below points
You are doing post request to the server
Make sure that the POSR URL is “https://oauth-login.cloud.huawei.com/oauth2/v3/token”.
Do not include post parameters in the URL, Add below parameters in body of POST request(If you use postman tool you can find the feilds for adding parameters)
grant_type=client_credentials
client_id= Your Client ID
client_secret= Your Client secret
For more details about fetching the access token, please refer the below link:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/open-platform-oauth-0000001053629189-V5#EN-US_TOPIC_0000001053629189__section12493191334711
I can't understand how to make OAuth 1.0 POST request using Retrofit library in Android.
This is the OAuth 1.0 Post request which I made in Postman
Help please, I can not understand how to transfer data such as consumer key, consumer secret, callbakurl to the request method, I think it is not supposed to be by annotations such as #Header or #Query. Also, I do not understand how to indicate in the request method that it is OAuth 1.0 and also that it is Authorization.
And also I get a response in the URL format. How can I get the response in the JSON format?
Thank you
I'm send data to rest service using retrofit and it works but when server crash and i need to test the api in postman but when using postman data is null,i can see that data are delivered using dump and die but when trying to access it return null
#POST("adToCart")
Call<CartDataResponse> addToCart(#Body CartData cartData);
As your request body is CartData, you can just simply use Gson.toJson(cartData) where, if you're using google Gson libray with retrofit and cartData is an object of CartData.java or the request model class. Print that value of the json which you have got from Gson.toJson(cartData), copy the json and put it into the body portion of postman and make sure that you have fill the hearder and correct endpoint, Then hit 'send' button which will give you your expected response. If not please share your steps for confirmation.
When making a request with Retrofit using an OKHttp Client with interceptors to add headers:
(Authorization: Bearer + access_token)
(User-Agent: "user_agetn_as_described_by_reddit")
Using the oauth.reddit.com/.json URL as recommended by Reddit, I get a 403. Now, when I do this same thing on Postman or something similar, I get a 200 and the expected JSON.
Is anyone aware of something related to Android or Retrofit or OKHttp that could be causing me this pain?
I was using the auth code instead of the access_token to make my requests. A mistake from my side. You should use the auth code to make a token request.
Having issue in postman can't send post request to the server.
So I have
#GetMapping("/{id}")
public blablabla (#PathVariable long id )
#PostMapping("/scan")
public blablablabla(){}
Somehow when I send post request for /scan via postman it returns
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
nested exception is java.lang.NumberFormatException: For input string: \"scan\
But it works fine in my android application.
Is this postman issue?
Thank you
I've got the answer..
In postman, I send http request to my https server.
So it's redirecting it making it a GET request instead of my POST request.