2013-05-01 56 views
1

我试图使用Apache HTTP将映像发布到REST服务发布我的例子是。由于输入结束而没有映射到对象的内容

POST/Example/HTTP/1.1 User-Agent:curl/7.23.1 libcurl/7.23.1 OpenSSL/0.9.8r Host:www。 Content-Length:32741 内容类型:multipart/form-data;内容类型:multipart/form-data;内容类型:multipart/form-data; border = --------- 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”:“没有要映射到Object的内容,输入“,”correlationId“:”9331d2343b721“}

我真的被卡住了,并会感谢任何帮助!

+0

尝试通过另一个平台发送http请求,以检查问题是在输入还是在代码中。我推荐使用Chrome的“高级REST客户端” – Rotem 2013-05-01 09:46:46

+0

这条消息是否意味着它收到了一个不期望或没有收到完整文件的对象? – user1240059 2013-05-01 12:07:24

+0

你得到一个服务器响应,所以问题不在于连接,而是在数据中,它可能是你编码它的方式或数据本身。尝试通过直接通过休息客户端发送请求来找出问题所在 – Rotem 2013-05-01 12:12:29

回答

0

你应该检查你是否设置了“content-length”标题。

相关问题