我无法从 Android 向我的数据库发送 GCM registration_id。我的服务器上有一个脚本,如果我输入“....name.php?regid=APA91bHmcD3_yZijf7dmmWlPiyi39Zx2kRTVHdI”它将起作用。但是,当我尝试通过 Android 发送它时,它不会。
这是我的代码:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.domain.com/newnotifier.php");
Log.d("TAG", regid);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("regid", regid));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
只需要知道为什么这不起作用。我查看了我的 logcat,它显示了整个 id 被发送过来。
谢谢,
编辑:它没有给出错误,它只是没有在数据库中显示任何内容。编辑 2:PHP 代码
$con = mysql_connect($mysql_host,$mysql_user,$mysql_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ($con)
{
}
mysql_select_db($mysql_database, $con);
name1 = $_REQUEST['regid'];
$sqldo = mysql_query("INSERT into users(regid) VALUES('".$name1."')");