I'm using RoboSpice Google Http Java Client module
and I'm successfully executing POST
request using JSON
data.
Problem : My problem is now I've to attach byte[]
data in POST
request but I'm unable to find any way to do this with RoboSpice Google Http Java Client module
.
Here is my code snippet :
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());
}
}
I tried using Multipart HTTP Requests
but it doesn't work.