500 Internal server error Android HttpPost file upload

大兔子大兔子 提交于 2019-12-12 02:23:51

问题


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();

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).

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

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

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/31550910/500-internal-server-error-android-httppost-file-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!