0
这里是我的代码发送一些数据到php服务器使用HttpPost Json格式。我如何上传图像以及数据?如何在Android中使用HttpPost将图像上传到服务器?
HttpPost httppost = new HttpPost(urlToSendCheckListReport);
JSONObject json = new JSONObject();
// prepare JSON data:
json.put("tag_id", tagID);
json.put("building_id", buildingID);
json.put("timestamp", new SimpleDateFormat("dd-MM-yyyy, HH:mm:ss").format(Calendar.getInstance().getTime()));
JSONArray postjson=new JSONArray();
postjson.put(json);
// Post the data:
httppost.setHeader("json", json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
HttpResponse response = new DefaultHttpClient().execute(httppost);
if(response != null)
{
.....Read the response
}
在此先感谢
检查http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-或文件 - 使用 - HTTP-POST-多部分/ –