Looks like you're using Spring for Android
. Judging that error message it seems Spring forces the content type to be application/json
, while I believe you're trying to send application/x-www-form-urlencoded
. So set this Content-Type
header:
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
Spring will know then to match the proper MessageConverter
. More info on this here.
EDIT: Also, you're supposed to send the request data in POST data, not in request URI. Move that to a MultiValuesMap
. Have a look at the link I gave you how to post such data. A complete documentation on these can also be found here.
EDIT2 You need to set the MessageConverter
for your response as well. Something like:
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
headers.setAccept(acceptableMediaTypes);
EDIT3 If you need to send files, consider using Resource
, to be more specific InputStreamResource
. But there is a trick: you need to provide the file name and the file size, otherwise your request will crash. Something like:
Resource res = new InputStreamResource(context.getContentResolver().openInputStream(itemImage)) {
@Override
public String getFilename() throws IllegalStateException {
return fileInfo.getFileName();
}
@Override
public long contentLength() throws IOException {
return fileInfo.getFileSizeInBytes();
}
};