2

私は使用しており、データを使用してリクエストをRoboSpice Google Http Java Client module正常に実行しています。POSTJSON

問題: 私の問題は、リクエストにbyte[]データを添付する必要POSTがあることですが、これを行う方法が見つかりません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たけどダメ。

4

1 に答える 1

0

ここでこの回答を確認してください https://stackoverflow.com/a/17151284/881771 呼び出す前に、loadFromNetwork メソッドに FileUpload ロジックを追加できます。

request.execute().parseAs(getResultType());
于 2014-02-04T15:46:26.113 に答える