Код состояния 500 во время загрузки многостраничного изображения объекта на сервер в коде Android.
Форма HTML: (можно успешно добавить изображение на сервер)
<form method="post" action="http://xyz/upload_picture" enctype="multipart/form-data">
Sample Picture Upload Form Submit
<br/><br/>
API key: <input type="text" name="key" value="abc"><br/><br/>
Login: <input type="text" name="login" value="text"><br/>
Password: <input type="password" name="password" value="text"><br/><br/>
Property ID:<input type="text" name="property_id" value="111"><br/>
Picture File:<input type="file" name="picture"><br/><br/>
<br/><br/>
<input type="submit" name="" value="Upload Picture"><br/>
</form>
Android-код: (дает код состояния 500)
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://xyz/upload_picture");
try {
MultipartEntity entity = new MultipartEntity();
entity.addPart("key", new StringBody("abc"));
entity.addPart("login", new StringBody("abc"));
entity.addPart("password", new StringBody("test"));
entity.addPart("property_id", new StringBody("111"));
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM).toString()
+ "/Camera/Test.jpg");
entity.addPart("picture", new FileBody(file));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
Log.e("test", "SC:" + response.getStatusLine().getStatusCode());
HttpEntity resEntity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.e("test", "Response: " + s);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}