Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a HttpEntity

I'm trying to update to the latest version (1.4.9) of com.loopj.android:android-async-http where org.apache.http was replaced with cz.msebera.android.httpclient.

At the moment I use:

StringEntity entity = new StringEntity("some data");
client.post(static_context, getAbsoluteUrl(url), entity, "application/json", responseHandler);

So I thought I can just cast it to HttpEntity which is not the case.

Caused by: java.lang.ClassCastException: org.apache.http.entity.StringEntity cannot be cast to cz.msebera.android.httpclient.HttpEntity

So my question is how can I create a HttpEntity with my data or is there a better way to create a post request with data in the body?

like image 498
Sir l33tname Avatar asked Oct 22 '25 01:10

Sir l33tname


1 Answers

It looks like you import the wrong StringEntity class.

Assuming the cz.msebera.android.httpclient still has a StringEntity, you should be able to

import cz.msebera.android.httpclient.entity.StringEntity

instead of

import org.apache.http.entity.StringEntity
like image 73
Floern Avatar answered Oct 23 '25 15:10

Floern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!