2011-12-16 84 views
-4

我有以下代码:卷曲PHP代码

curl -X PUT -u "<app key>:<secret key>" \ 
    -H "Content-Type: application/json" \ 
    --data '{"alias": "myalias"}' \ 
    https://go.xxx.com/api/device_tokens/<token>/ 

我试图将其转换为PHP的,但似乎没有工作,我不知道是什么问题。

这就是我试图

<? 
     $token = $_POST["token"]; 
     $al = $_POST["alias"]; 
     exec('curl -X PUT -u "_rEUqXXXmSVEBXXuMfdtg:vpB2XXXXX_2HZ_XXXX7t-Q" \ 
     -H "Content-Type: application/json" \ 
     --data \'{"alias": "'.$al.'"}\' \ 
     https://go.xxx.com/api/device_tokens/'.$token'/'); 
?> 
+5

PHP中有一个卷曲库。 (-1,因为你从未指定错误是什么,另一个让人猜测问题) – ajreal 2011-12-16 11:35:01

+0

我认为应该删除你的行尾反斜杠(假设你允许使用exec来运行卷曲)。 – pritaeas 2011-12-16 11:35:42

回答

3
$ch = curl_init(); 
    // echo $url; die; 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_POST, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("custom: header")); 
    $returned = curl_exec($ch); 
    curl_close ($ch); 

还有更多的选择,你在PHP docs想要的东西,他们不帮忙。