1
我想用的API上https://build.phonegap.com/docs/api從命令行PhoneGap的API捲曲到PHP
給它需要以下curl命令來運行,這將返回一個令牌建立PhoneGap的應用。
$ curl -u [email protected] -X POST "" https://build.phonegap.com/token
這個捲曲語句在命令行中對我有效。我想在php中使用它。我嘗試了下面給出的PHP代碼,但它不工作。
$username = "[email protected]";
$password = "PASSWORD";
$target_url = "https://build.phonegap.com/token"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close ($ch);
echo $result;
謝謝您的幫助。 –
它爲我工作。 –