如何使用JSON数据使用Robospice Google HTTP Java客户端模块上传文件



我正在使用RoboSpice Google Http Java Client module,并且我成功地使用JSON数据执行POST请求。

问题:我的问题现在我已经在POST请求中附加了byte[]数据,但是我无法找到使用RoboSpice Google Http Java Client module的任何方法。

这是我的代码段:

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,但它不起作用。

在此处查看此答案https://stackoverflow.com/a/17151284/881771您可以在调用

之前将FileUpload逻辑添加到LoadFromnetwork方法中
request.execute().parseAs(getResultType());

最新更新