在web上传图像:获取html源代码作为响应

时间:2012-02-29 12:02:46

标签: android web-services

我正在尝试在网络服务器上传图片,但每当它尝试时它都会发送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("b@gmail.com.jpg", body);

post.setEntity(entity);


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

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

提前致谢!!!

1 个答案:

答案 0 :(得分:1)