-1

here is an example of my code. (Dependencies implementation 'com.loopj.android:android-async-http:1.4.11')

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

asyncHttpClient.addHeader("secret", "123");

JSONObject jsonParams = new JSONObject();

onParams.put("name", "Jon");

asyncHttpClient.post(menu.this, "http://192.168.1.104:8000/", jsonEntity, "application/json", new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    super.onSuccess(statusCode, headers, response);

                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse ) {
                    super.onFailure(statusCode, headers, throwable, errorResponse);
                     //////////////??????????????????????????????????/////////////////////////
                }
            });

If the server does not respond, I get into the onFailure method with a TimeOut error, how can I get the body of my request that I sent ( onParams.put("name", "Jon");) ?

i want to get the body of the request i sent

  • 2
    `jsonEntity` and `onParams` are available in that scope..... – Antoniossss Jan 27 '23 at 12:08
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 28 '23 at 09:34

1 Answers1

0

You could just use the reference from above. Also you made a little error in the second use of jsonParams, you typed onParams here.

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

asyncHttpClient.addHeader("secret", "123");

JSONObject jsonParams = new JSONObject();

jsonParams.put("name", "Jon");

asyncHttpClient.post(menu.this, "http://192.168.1.104:8000/", jsonEntity, "application/json", new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    super.onSuccess(statusCode, headers, response);

                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse ) {
                    super.onFailure(statusCode, headers, throwable, errorResponse);
                    log.d("TAG", jsonParams);
                }
            });
MESP
  • 486
  • 2
  • 17