我正在尝试更新到 com.loopj.android:android-async-http
的最新版本 (1.4.9),其中 org.apache.http
替换为 cz.msebera.android.httpclient
。
目前我使用:
StringEntity entity = new StringEntity("some data");
client.post(static_context, getAbsoluteUrl(url), entity, "application/json", responseHandler);
所以我认为我可以将它转换为 HttpEntity
,但事实并非如此。
Caused by: java.lang.ClassCastException: org.apache.http.entity.StringEntity cannot be cast to cz.msebera.android.httpclient.HttpEntity
所以我的问题是如何使用我的数据创建一个 HttpEntity
或者是否有更好的方法来创建一个包含正文数据的发布请求?
最佳答案
您似乎导入了错误的 StringEntity
类。
假设 cz.msebera.android.httpclient
仍然有一个 StringEntity
,你应该能够
import cz.msebera.android.httpclient.entity.StringEntity
代替
import org.apache.http.entity.StringEntity
关于java - 创建一个 HttpEntity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251578/