我不明白我的 _POST 是空的
我创建了一个 JSONOBJECT 我将它传递给 HTTPPost 像这样:
HttpPost post = new HttpPost(URL);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(se);
response = client.execute(post);
然而它显示为一个空数组
这是完整的代码
创建我 JSON 对象(可以调试它并观察它填充
public static final JSONObject GetJSONObject(Customer customer) {
try {
JSONObject values = new JSONObject();
values.put(Customer.KEY_NAME, customer._name); // Contact Name
values.put(Customer.KEY_PH_NO, customer._phone); // Contact Phone
values.put(Customer.KEY_EMAIL, customer._email);
values.put(Customer.KEY_UUID, customer._UUID);
values.put(Customer.KEY_GEOUUID, customer._geoUUID);
values.put(Customer.KEY_SALESREPUUID, customer._salesRepUUID);
values.put(Customer.KEY_CUST_LAST_UPDATE, customer.last_update);
values.put(Customer.KEY_CUST_NOTES, customer._notes);
return values;
} catch (JSONException e) {
Log.d("ERROR", e.getMessage());
System.exit(1);
}
return null;
}
开始发送线程
ma.ShowToastMsg("Updating Contract To mySQL" + customer._name);
mh.sendJSONTHREAD("http://.php",
GetJSONObject(customer));
public void sendJSONTHREAD(final String URL, final JSONObject json) {
new Thread(new Runnable() {
public void run() {
sendJson(URL, json);
}
}).start();
}
发送
public void sendJson(final String URL, final JSONObject json) {
Looper.prepare(); // For Preparing Message Pool for the child Thread
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
// Limit
HttpResponse response;
try {
HttpPost post = new HttpPost(URL);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(se);
response = client.execute(post);
/* Checking response */
if (response != null) {
Log.d("RESPONSE", EntityUtils.toString(response.getEntity()));
//InputStream in = response.getEntity().getContent(); // Get the
// data in
// the
// entity
//Log.d("HTTPPOST", in.toString());
}
} catch (Exception e) {
e.printStackTrace();
// createDialog("Error", "Cannot Estabilish Connection");
}
Looper.loop(); // Loop in the message queue
}
和 PHP 方面的事情
include("settings.php");
mysql_connect($loginURL,$username,$password);
@mysql_select_db($database) or die("-9");
echo var_dump($_POST);
$varname = mysql_real_escape_string(strip_tags($_POST['name']));
$varemail = mysql_real_escape_string(strip_tags($_POST['email']));
$varphone = mysql_real_escape_string(strip_tags($_POST['phone']));
$varUUID = mysql_real_escape_string(strip_tags($_POST['UUID']));
$vargeopointUUID = $_POST['geopointUUID'];
echo var_dump($_POST);
echo var_dump($_POST) - 返回数组(0){}