2012-02-29 27 views
2

我想上傳圖片在網絡服務器上,但每當它試圖發送給我的HTML源代碼作爲響應和圖像沒有上傳到那裏。我的代碼是:上傳圖片在網上:獲取HTML源代碼作爲迴應

HttpClient client = new DefaultHttpClient(); 

HttpPost post = new HttpPost(url); 

ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); 
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); 
byte[] buffer = byteStream.toByteArray(); 

ByteArrayBody body = new ByteArrayBody(buffer,"profile_image"); 


MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

entity.addPart("[email protected]", body); 

post.setEntity(entity); 


System.out.println("post entity length "+entity.getContentLength()); 
ResponseHandler handler = new BasicResponseHandler() ; 

String response = client.execute(post,handler); 

在此先感謝!

+0

接觸您的服務器端的團隊,什麼是服務器期待,他已經使用一些回聲返回HTML字符串,而不是正確的響應。 – jeet 2012-02-29 12:14:55

+0

是的,可能會檢查出來! – 2012-03-01 16:22:42

回答