【发布时间】:2014-02-26 17:45:16
【问题描述】:
我正在使用RoboSpice Google Http Java Client module,并且我正在使用JSON 数据成功执行POST 请求。
问题:我的问题是现在我必须在POST 请求中附加byte[] 数据,但我无法找到任何使用RoboSpice Google Http Java Client module 的方法。
这是我的代码 sn-p:
public class SaveUserProfile_Request extends GoogleHttpClientSpiceRequest<SaveUserProfile> {
private String apiUrl;
private JSONObject mJsonObject;
private String filePath;
public SaveUserProfile_Request(JSONObject mJsonObject, String filePath) {
super(SaveUserProfile.class);
this.apiUrl = AppConstants.GLOBAL_API_BASE_ADDRESS + AppConstants.API_SAVE_PROFILE;
this.mJsonObject = mJsonObject;
this.filePath = filePath;
}
@Override
public SaveUserProfile loadDataFromNetwork() throws IOException {
Ln.d("Call web service " + apiUrl);
HttpRequest request = getHttpRequestFactory().buildPostRequest(new GenericUrl(apiUrl),
ByteArrayContent.fromString("application/json", mJsonObject.toString()));
request.setParser(new JacksonFactory().createJsonObjectParser());
return request.execute().parseAs(getResultType());
}
}
我尝试使用Multipart HTTP Requests,但它不起作用。
【问题讨论】:
标签: java android json robospice google-http-client