android - 在网络上上传图像 : getting html source code as response

标签 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);

提前致谢!!!

最佳答案

关于android - 在网络上上传图像 : getting html source code as response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9498802/

相关文章:

java - BebopVideoView 到 Mat

android - 如何将我的指南针指向麦加?

C# axis2 客户端

java - 带有 MVC 的 Spring 3 JSON

.net - 如何使用关键字以编程方式搜索谷歌并获得我的网站排名?

web-services - 有状态的 Web 服务有多好和/或有多必要?

android - java.lang.NullPointerException React Native

java - 如何将 Activity 转换为图像

android - 在屏幕方向更改android上调整视频 View

c# - 实例化 Web 服务时的最佳做法是什么