我正在使用PhoneGap Build API上传文件并创建其apk。您可以在这里检查https://build.phonegap.com/docs/write_api
我在使用php实现curl时遇到问题。命令行上的以下curl语句运行正常。
$ curl -F file=@/Users/alunny/index.html -u andrew.lunny@nitobi.com -F'data = {“title”:“API V1 App”,“package”:“com.alunny.apiv1 “,”版本“:” 0.1.0“,”创建方法“:”文件“}'https://build.phonegap.com/api/v1/apps
当我尝试使用php编写此代码时出现错误。我写了下面的代码。
$username = "email";
$password = "password";
$target_url = "https://build.phonegap.com/api/v1/apps";
$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_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$post = array(
"file"=>"@www.zip",
"data"=>json_encode(array("title"=>"My Test App","package"=>"com.alunny.apiv1","version"=>"0.1.0","create_method"=>"file"))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close ($ch);
通过运行此代码,我收到此错误“未指定create_method:file,remote_repo或hosted_repo”
请帮助我解决这个问题。
谢谢
最佳答案
尝试shell_exec()函数:
$cmd = "https://build.phonegap.com/api/v1/apps";
$out = shell_exec($cmd);
$data = json_decode($out);
关于php - PhoneGap Build API : CURL Command Line to PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12272232/