我将多部分表单数据发送到我的服务器,但它给出了内部服务器错误。相同的请求在邮递员中给出了成功的响应,但是当我在android中执行它时会抛出内部服务器错误。有人能帮我吗?谢谢。 以下是我的代码
private class UpdateTask extends AsyncTask<String, String,String> {
protected String doInBackground(String... urls) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xx.xxx.xx/xx");
httppost.addHeader("Authorization", "xxxx.xxxx.xxx");
try {
FileBody bin = new FileBody(new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM).toString()
+ "/Camera/image.jpg"));
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("image", bin);
httppost.setEntity(reqEntity);
System.out.println("Requesting : " + httppost.getRequestLine());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
long startTime = System.currentTimeMillis();
String responseBody = httpclient.execute(httppost, responseHandler);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
}
return null;
}
}
我的Logcat
org.apache.http.client.HttpResponseException: Internal Server Error
org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:76)
org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:63)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:802)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:772)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:761)
com.sukshi.reliancetest.MainActivity$UpdateTask$override.doInBackground(MainActivity.java:72)
com.sukshi.reliancetest.MainActivity$UpdateTask$override.access$dispatch(MainActivity.java)
com.sukshi.reliancetest.MainActivity$UpdateTask.doInBackground(MainActivity.java:0)
com.sukshi.reliancetest.MainActivity$UpdateTask.doInBackground(MainActivity.java:45)
android.os.AsyncTask$2.call(AsyncTask.java:292)
java.util.concurrent.FutureTask.run(FutureTask.java:237)
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:818)