500 Internal server error Android HttpPost file up

2019-09-05 01:42发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-05 01:53

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.

查看更多
登录 后发表回答