同样的post请求代码在Java和android中执行结果不同。
同样的代码,在JAVA和android里得到的httpresponse不一样为什么呢?
主要代码如下。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
FileBody bin = new FileBody(new File(fileName));
StringBody comment = new StringBody("Filename: " + fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", bin);
reqEntity.addPart("comment", comment);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
java得到的response内容
android得到的:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出现不同结果的原因可能是
HttpClient
的版本不同造成的,第二个结果也是由HTTP 302
响应后重定向到新的URL
中的,区别在于Java
中默认没有进行重定向。解决方法就是统一重定向方式
参考:
http://stackoverflow.com/questions/5169468/handling-httpclient-redirects
http://stackoverflow.com/questions/3658721/httpclient-4-error-302-how-to-redirect