Estou realizando um teste de requisição com Authorization Bearer Token A resposta é essa {'status':'ok'} mas já tentei usando {"status":"ok"}. A conexão é efetuada, porém cai no onfailure, retornando o seguinte erro: Unexpected character (''' (code 39)): was expecting double-quote to start field name at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 3]. Tenho outras requisições sem o token e não acontece o problema, somente nessa.
public class ProtectedRetrofitInitializer {
private final Retrofit retrofit;
public ProtectedRetrofitInitializer() {
final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(JacksonConverterFactory.create())
.client(client)
.build();
}
public ProtectedService service() {
return retrofit.create(ProtectedService.class);
}
}
/Interface
public interface ProtectedService {
@GET("url")
Call<Map<String, String>> get(@Header("Authorization") String token);
}
//Chamada
Call<Map<String,String >> call = new ProtectedRetrofitInitializer().service().get(requestToken);
call.enqueue(new retrofit2.Callback<Map<String, String>>() {
@Override
public void onResponse(Call<Map<String, String>> call, Response<Map<String, String>> response) {
Log.i("--->", "Response" + response.body());
}
@Override
public void onFailure(Call<Map<String, String>> call, Throwable t) {
Log.e("--->", "Erro: "+ t.getMessage());
}
});
//Resposta
<-- 200 OK
Expires: 0
Connection: keep-alive
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: application/octet-stream
Content-Length: 15
Date: Wed, 24 Apr 2019 13:53:20 GMT
{'status':'ok'}
<-- END HTTP (15-byte body)
Erro: Unexpected character (''' (code 39)): was expecting double-quote to start field name
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 3]