我正在尝试使用 Apache HTTP Post 将图像发布到 REST 服务,我的示例是。
POST /Example/ HTTP/1.1 用户代理:curl/7.23.1 libcurl/7.23.1 OpenSSL/0.9.8r 主机:www。** .com/443 Accept: application/json Authorization: Bearer access token Content-Length: 32741 Content-Type: multipart/form-data; 边界=---------a24d743fe
我正在使用以下代码。
HttpPost httppost = new HttpPost(str);
StringEntity se;
try {
httppost.setHeader("Content-Type","multipart/form-data;boundary=---------a24d743fe");
httppost.addHeader("Accept","application/json");
httppost.addHeader("Authorization", "Bearer " + token.getAccessToken());
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
Log.d("uri",getRealPathFromURI(imageUri));
File file= new File(getRealPathFromURI(imageUri));
if(file.exists())
{
Log.d("file","exists");
entity.addPart("image data", new FileBody(file));
}
httppost.setEntity(entity);
HttpClient httpclient = new DefaultHttpClient();
BasicHttpResponse httpResponse =
(BasicHttpResponse) httpclient.execute(httppost);
Log.d("HTTPStatus",httpResponse.getStatusLine().toString());
但我收到以下错误。
05-01 10:18:31.400: D/response(1872): {"errorCode":600000,"errorType":"service_error","message":"由于输入结束,没有要映射到对象的内容","相关标识“:”9331d2343b721“}
我真的被困住了,不胜感激!