わかりません_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)-array(0){}を返します