Ich lese https://futurestud.io/blog/retrofit-2-log-requests-and-responses und machte es.Wie bekomme ich Json Log mit Retrofit2 im Android Studio?
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.interceptors().add(logging);
client = builder.build();
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(LoginApiService.Login_API_URL)
.build();
Aber es zurückgegebene Ergebnis wie
09-08 05:12:24.219 25389-26089/com.example.keepair.myapplication D/OkHttp: --> POST http://ec2-52-78-138-143.ap-northeast-2.compute.amazonaws.com:8000/rest-auth/login/ http/1.1
09-08 05:12:24.219 25389-26089/com.example.keepair.myapplication D/OkHttp: Content-Type: application/json; charset=UTF-8
09-08 05:12:24.219 25389-26089/com.example.keepair.myapplication D/OkHttp: Content-Length: 46
09-08 05:12:24.219 25389-26089/com.example.keepair.myapplication D/OkHttp: --> END POST
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: <-- 400 Bad Request http://ec2-52-78-138-143.ap-northeast-2.compute.amazonaws.com:8000/rest-auth/login/ (96ms)
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: Date: Wed, 07 Sep 2016 20:11:27 GMT
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: Server: WSGIServer/0.2 CPython/3.4.3
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: Vary: Accept
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: Allow: POST, OPTIONS
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: X-Frame-Options: SAMEORIGIN
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: Content-Type: application/json
09-08 05:12:24.314 25389-26089/com.example.keepair.myapplication D/OkHttp: <-- END HTTP
Es ist nicht genug.
Weil ich RESTful api und json Typ,
- bin mit Ich möchte json Anfrage prüfen, ob ich auf api und JSON-Antwort senden, die von api kommt. Zum Beispiel, {"hi": "tschüß"}, vollständige Information der json Anfrage und Antwort.
- Zusätzlich möchte ich genau wissen, was über Header von meiner Anwendung gesendet hat.
Was soll ich tun?