YtotheZ
YtotheZ

Reputation: 463

Android Asynchronous Http Client (Loopj) POST request with headers and body

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

Upvotes: 0

Views: 3461

Answers (1)

noni
noni

Reputation: 2947

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)

Upvotes: 6

Related Questions