這是我用於向我的應用發送通知的代碼。cURL不會顯示PHP的整個GET參數
include("connection.php");
include("utils.php");
$Info = mysql_fetch_array(mysql_query("SELECT * FROM data WHERE iddata = ".$_GET["dataId"]));
$ownerInfo = mysql_fetch_array(mysql_query("SELECT * FROM dataUsers WHERE id = ".$dataInfo['id']));
$data = mysql_fetch_array(mysql_query("SELECT dataUsers.id, dataUsers.token, data.idData, data.id FROM data INNER JOIN data ON data.iddata = '".$_GET["data"]."' AND data.id = dataUsers.id"))["token"];
$datagOwnerDeviceToken = getDeviceTokenFromUserToken($dataOwnerToken);
//call server where simplePush.php is located -ports opened-
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "http://www.myserver.com/sendNotif.php?msg=hello guys&deviceToken=xxxxxxxxxxxx",
CURLOPT_USERAGENT => 'whatever'
));
$resp = curl_exec($curl);
curl_close($curl);
的問題是,我收到通知,而不是「好傢伙」,我已收到,「你好」,那是說,串偷竊時,它開創一個空格。我認爲這可能是由於編碼,但我真的不知道如何使其工作。
如果我將msg參數更改爲msg = helloguys,我會收到整個字符串。所以空白處有問題。
非常感謝。
這是現在的實際代碼:
$curl = curl_init();
curl_setopt_array($捲曲,陣列( CURLOPT_RETURNTRANSFER => 1,
$url = "http://server.com/notifications.php?".http_build_query(array(
'msg' => "hello this is ".$dataInfo["wastringText"],
'deviceToken' => $dataOwnerDeviceToken
));
回聲 「這是我的URL:」。$網址; curl_setopt_array($捲曲,陣列( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $網址, CURLOPT_USERAGENT => '無論' ));
$ resp = curl_exec($ curl); curl_close($ curl);
它可能會幫助你 $ url = urlencode(YOUR_URL_STRING); CURLOPT_URL => $ url –
@SergeyBelyakov你不應該在整個URL上使用urlencode(),只是每個參數。 – Barmar
仍然存在將代碼放置在標籤中的問題。有人編輯? –