0

I have an instance of AsyncHttpClient and i want to print the complete request that goes to the Server.

private static AsyncHttpClient client = new AsyncHttpClient();

public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    String urlToSend = getAbsoluteUrl(url);
    client.addHeader("Authorization","Basic "+ Base64.encodeToString((BuildConfig.BASIC_AUTH_USER+":"+BuildConfig.BASIC_AUTH_PWD).getBytes(),Base64.NO_WRAP));
    client.setLoggingLevel(Log.ERROR);
    client.setTimeout(DEFAULT_TIMEOUT);
    client.post(urlToSend, params, responseHandler);
}

I am able to get response and is able to see header and other stuff while debugging. But i want to print complete request made to the server in logger i.e url appended with header and body.

Shivam
  • 29
  • 11
  • You can use okHttp client with interceptor, have look [this](https://stackoverflow.com/a/46535959/5110595) – Hemant Parmar Oct 04 '19 at 05:58
  • @HemantParmar i would have used OkHttp or retrofit, but this code is of an existing product which we cannot change. Is there any way to log request using AsyncHttpClient? – Shivam Oct 04 '19 at 06:02
  • I read the docs and found [this](https://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html#setLoggingEnabled-boolean-) method, have a look it, hope it will help you. – Hemant Parmar Oct 04 '19 at 06:29
  • No it is still printing the response but not request :-( @HemantParmar – Shivam Oct 04 '19 at 06:41

0 Answers0