500内部服务器错误Android HttpPost文件上传 [英] 500 Internal server error Android HttpPost file upload

查看:194
本文介绍了500内部服务器错误Android HttpPost文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我注意到,当我尝试使用HttpPost将图像上传到服务器时遇到此错误,我在Eclipse中使用的代码是:

Lately I've noticed I get this error when I try to upload an image to my server using HttpPost, the code I use in Eclipse is this:

                    HttpPost httpPost = new HttpPost((String) params[0]);
                    Uri uri = (Uri) params[2];
                    String fileName = getFileName(uri);
                    if (fileName == null) fileName = "image";
                    InputStream inputStream = getContentResolver().openInputStream(uri);

                    HttpEntity mpEntity = MultipartEntityBuilder.create().addPart("place", new StringBody((String) params[3])).addBinaryBody("appuploadfile", inputStream, ContentType.create("image"), fileName).build();
                    httpPost.setEntity(mpEntity);
                    httpPost.setHeader("User-Agent", userAgent);
                    httpPost.setHeader("Cookie", cookie);
                    httpResponse = httpclient.execute(httpPost);
                    inputStream.close();

我的主机正在使用LiteSpeed,并且一直工作到现在,但是他们可能已更新了某些内容,因此我的代码不再兼容了?如果将服务器更改为PC上的本地服务器,则可以正常运行,我只会在主机上收到错误消息.有人知道什么地方可能出问题吗?我确实尝试对应用程序进行嗅探,以查看其确切发送的内容,然后将其与浏览器(firefox)进行比较,数据看起来有些不同,并且发送的方式似乎有所不同(请注意,文件上传可以在浏览器中正常进行,只是无法在我的android应用中正常工作.

My host is using LiteSpeed and it has worked until now but they probably updated something so my code is not compatible anymore? If I change the server to my local one on my PC it works perfectly, I only get the error with my host. Does anybody know what could be wrong? I did try to packet sniff my app to see what it is sending exactly, and comparing it with the browser (firefox) the data looks a bit different and seems to be sent differently (note that the file upload works fine from a browser, it just doesn't work anymore from my android app).

这是从我的应用程序发送时的样子: http://justpaste.it/mi11

This is how it looks like when it is sent from my app: http://justpaste.it/mi11

这是从浏览器发送的样子(firefox,它可以正常工作): http://justpaste.it/mi1c

This is how it looks like when it is sent from a browser (firefox, and it works fine): http://justpaste.it/mi1c

谢谢!

推荐答案

HTTP错误500表示内部服务器错误.也就是说,该错误是在服务器中,而不是在您的应用程序中.您需要检查服务器的日志以查看造成该问题的原因并在那里进行修复.

HTTP error 500 means Internal Server Error. That is, the error is in the server, not in your application. You need to check the server's logs to see what caused it and fix it there.

这篇关于500内部服务器错误Android HttpPost文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆