我最近转向 Retrofit,我想用 Retrofit 替换这个 httpost 集实体。我该怎么做。
JSONObject jsonObject = new JSONObject();
jsonObject.put("childId", childId);
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObject.toString());
httpPost.setEntity(entity);
这就是我想做的,但它确实奏效了,
Observable<Item> getListOfFeed(@Body StringEntity params);
最佳答案
终于找到答案了,添加一个自定义的TypedJsonString类,
public class TypedJsonString extends TypedString {
public TypedJsonString(String body) {
super(body);
}
@Override public String mimeType() {
return "application/json";
}
}
将我的 json 对象转换为 TypedJsonString,
TypedJsonString typedJsonString = new TypedJsonString(jsonObject.toString());
如下更改 api 类,
Observable<Item> getListOfFeed(@Body TypedJsonString typedJsonString);
关于android - http post setEntity 使用改造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939650/