同じ文字列をphpファイルに送信する必要がある2つの同じアプリに取り組んでいます。PHPでこのコードを使用してチェックすると、iOSのものはGETになります。
file_put_contents('dump.txt', "POST: \n" . print_r($_POST, true) . "\n\n\n GET: \n" . print_r($_GET, true));
しかし、Android のものは POST ですが、まったく同じである必要があります。PHP の作業部分を既に構築しているため、これ以上変更することはできません。
ここに私のアンドロイドコードがあります:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://Myserver.com/default.php");
json = new JSONObject();
try {
json.put("id", "69403");
json.put("longitude", longi);
json.put("latitude", lat);
json.put("timestamp", time);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/// create StringEntity with current json obejct
try {
// StringEntity se = new StringEntity(json.toString());
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("data", json.toString()));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
System.out.println("send about to do post");
try {
response = httpclient.execute(httpost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("send post done");
HttpEntity entity = response.getEntity();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}