我有一個工作CLI捲曲CLI到PHP捲曲
curl -X POST \
-H "X-Parse-Application-Id: ID" \
-H "X-Parse-REST-API-Key: KEY" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"Giants",
"Mets"
],
"data": {
"alert": "The Giants won against the Mets 2-3."
}
}' \
https://api.parse.com/1/push
它返回一個字符串{"result":"success"}
但我的PHP捲曲
$post = json_encode(array('channels'=>array('Giants','Mets'),'data'=>array('alert'=>'The Giants won against the Mets 2-3')));
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://api.parse.com/1/push',
CURLOPT_HTTPHEADER => array(
'X-Parse-Application-Id: ID',
'X-Parse-REST-API-Key: KEY',
'Content-Type: application/json'
),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true
));
$res = curl_exec($ch);
if (curl_error($ch)) {
echo "Curl error: " . curl_error($ch);
}
curl_close($ch);
echo $res;
顯示消息「您要查找的頁面不存在「。然後下面一個「1」,這是$res
沒有錯誤
感謝
[轉換命令行卷曲到PHP捲曲]可能重複(http://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl) – Gajus