我试图通过上传五张图片来实现this,下面的一些表单数据是我用来实现任务的代码
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
File file1 = new File(selectedPath1);
File file2 = new File(selectedPath2);
File file3 = new File(selectedPath3);
File file4 = new File(selectedPath4);
File file5 = new File(selectedPath5);
String urlString="http:url.com";
try
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlString);
FileBody bin1 = new FileBody(file1);
FileBody bin2 = new FileBody(file2);
FileBody bin3 = new FileBody(file3);
FileBody bin4 = new FileBody(file4);
FileBody bin5 = new FileBody(file5);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("section", new StringBody("inventory"));
reqEntity.addPart("action", new StringBody("new"));
reqEntity.addPart("apron_id", new StringBody(stock_number_ele.getText().toString()));
reqEntity.addPart("nickname", new StringBody(nick_name_ele.getText().toString()));
reqEntity.addPart("location", new StringBody(location));
reqEntity.addPart("manufacture", new StringBody(manufacture));
reqEntity.addPart("core_material", new StringBody(core_material_ele.getText().toString()));
reqEntity.addPart("color", new StringBody(color_ele.getText().toString()));
reqEntity.addPart("Date_purchase", new StringBody(dop_ele.getText().toString()));
reqEntity.addPart("UID_no", new StringBody(gtin_uid_ele.getText().toString()));
reqEntity.addPart("serial", new StringBody(serial_ele.getText().toString()));
reqEntity.addPart("Batch", new StringBody(batch_lot_ele.getText().toString()));
reqEntity.addPart("Expiration", new StringBody(ed_ele.getText().toString()));
reqEntity.addPart("garment_type", new StringBody(description_ele.getText().toString()));
reqEntity.addPart("QTY", new StringBody(county_ele.getText().toString()));
reqEntity.addPart("user_id", new StringBody(SignInActivity.user_id));
if(selectedPath1!="NONE")
reqEntity.addPart("image1", bin1);
if(selectedPath2!="NONE")
reqEntity.addPart("image2", bin2);
if(selectedPath3!="NONE")
reqEntity.addPart("image3", bin3);
if(selectedPath4!="NONE")
reqEntity.addPart("image4", bin4);
if(selectedPath5!="NONE")
reqEntity.addPart("image5", bin5);
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
resEntity = response.getEntity();
final String response_str = EntityUtils.toString(resEntity);
if (resEntity != null) {
Log.i("RESPONSE",response_str);
}
}
catch (Exception ex){
Log.e("Debug", "error: " + ex.getMessage(), ex);
}
return resEntity.toString();
}
图像和数据似乎已发送,但服务器接收的数据没有响应和PHP脚本
响应 {"状态":0,"日期":"找不到任何部分"}
腓
elseif($section=="inventory")
{
if(empty($action))
{
$response=array("status"=>0,"data"=>"No action Found");
echo json_encode($response);
exit;
}
require_once("classes/class_inventory.php");
$inventory = new inventory();
switch($action)
{
case 'new':
$response=$inventory->action_inventory($_REQUEST);
echo json_encode($response);
exit;
case 'get':
$response=$inventory->get_inventory($_REQUEST);
echo json_encode($response);
exit;
}
} else {
$response=array("status"=>0,"date"=>" No section Found ");
echo json_encode($response);
exit;
}
提前致谢。