你好朋友我尝试了很多方法到这个购物车附加 url
url = "http://xxxxxxxxxxxx/index.php?option=com_storephotos&view=storephotos&storemp=storemp&imageid=73&task=storemp&device=android&mutirecords=[{imageid:1,size_id:8X11,cat_id:card,no_of_prints:1,addressid:26,user_id:91,device:android,imagedata:[B@41d46e98}]";
这是一个购物车,附加此键 mutirecords=,并发送多个图像,如果我点击 url 它会给出响应但图像不会保存在数据库中。如何使用 post 方法发送此购物车
//
protected Void doInBackground(Void... params) {
try {
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
if (data != null) {
System.out.println("aaaaa");
entity.addPart("userfile:", new ByteArrayBody(data,
"pic.jpg"));
} else {
System.out.println(",,,,,,,,,,,,,,,,,,,,,,");
data = "nopick...........".getBytes();
// entity.addPart("imagedata:", new
ByteArrayBody(data,
// "pic.jpg"));
}
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("imageid:",
"1"));
// .......
nameValuePairs.add(new BasicNameValuePair("size_id:", "8X11"));
nameValuePairs.add(new BasicNameValuePair("cat_id:", "card"));
nameValuePairs
.add(new BasicNameValuePair("no_of_prints:", "1"));
nameValuePairs.add(new BasicNameValuePair("addressid:", "26"));
nameValuePairs.add(new BasicNameValuePair("user_id:", "91"));
String as = "mmmlocation" + "},";
System.out.println("ass " + as);
nameValuePairs
.add(new BasicNameValuePair("device:", "android"));
for (int i = 0; i < nameValuePairs.size(); i++) {
try {
Log.d("sss", "vffff" + i);
System.out.println(nameValuePairs.get(i).getName()
+ " nnhhh "
+ new StringBody(nameValuePairs.get(i)
.getValue()));
Log.d("sss", "vffff" + i);
entity.addPart(
nameValuePairs.get(i).getName(),
new StringBody(nameValuePairs.get(i).getValue()));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
Log.d("respons", "image respons " + e);
e.printStackTrace();
}
}
HttpClient httpclient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httppost = new HttpPost(
"http://xxxxxxxxxxxxxx/index.php?option=com_storephotos&view=storephotos&storemp=storemp&imageid=73&task=storemp&device=android&mutirecords=");
Log.d("entity", "entity " + entity);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost,
localContext);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse = reader.readLine();
Log.d("re", "res" + sResponse);
// bitmapOrg.recycle();
//
} catch (Exception e) {
// // TODO: handle exception
if (dialog.isShowing())
dialog.dismiss();
Log.d("aaaaaaaaa", "aaaaaaaaa " + e);
}
return null;
// (null);
}