I'm trying to get a location like this:

Retrofit (Interface)

@FormUrlEncoded @POST("/geolocation/v1/geolocate") Call<GetGeolocation> getLocation(@Field("key") String key); 

And here I appeal to him:

 private Gson gson = new GsonBuilder().create(); private Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson)) .baseUrl("https://www.googleapis.com") .build(); private API api = retrofit.create(API.class); Call<GetGeolocation> googleLocation = api.getLocation("KEY"); googleLocation.enqueue(new Callback<GetGeolocation>() { @Override public void onResponse(Call<GetGeolocation> call, Response<GetGeolocation> response) { Log.d("Log:", "OK"); } @Override public void onFailure(Call<GetGeolocation> call, Throwable t) { Log.d("Log:", "Error"); } }); 

In response, I come

 Response{protocol=h2, code=400, message=, url=https://www.googleapis.com/geolocation/v1/geolocate} 

On the other hand, I send the exact same request through Postman

 https://www.googleapis.com/geolocation/v1/geolocate?key=KEY 

Everything comes to me correctly

Postman

enter image description here

  • Try Query instead of Field - YuriySPb
  • When sending a Query by the Post method, it gives an error (must be Field) And when I try to send GET, Google sends 404 error - Heaven
  • Show the request screen from the Posman - YuriySPb
  • screenshot - Heaven
  • Try to remove @FormUrlEncoded besides query - YuriySPb

1 answer 1

In the query you FormUrlEncoded you need to use Query instead of Field and remove FormUrlEncoded

 @POST("/geolocation/v1/geolocate") Call<GetGeolocation> getLocation(@Query("key") String key);