0

I am working on an android application, I am using "Android Asynchronous Http Client" (Loopj) library in order to handle all the requests to the server.

I need to send a POST request with headers and JSON body.

By looking to the available POST methods in the AsynchHttpClient.java I found those:

public void post(Context context, String url, Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler responseHandler)

public void post(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler)

Which one should I use? What is the difference between Header[], RequestParams and HttpEntity? Which one is considered to hold the headers and which the body of the request?

Thanks for any clarification

1 Answer 1

6

The difference between both methods are:


RequestParams: Additional POST parameters to be sent, in key=value format

HttpEntity: A raw entity to send, use this to send string/json/xml payloads.


If you want to post JSON, use HttpEntity, like ByteArrayEntity

Headers[], is an array to send the configuration headers of the request to your server. (Content-type, content-size, etc)

Sign up to request clarification or add additional context in comments.

1 Comment

How to add headers in post request while using loopj ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.