我正在尝试通过使用 laravel 框架实现 CURL将我的帐户与PHONEGAP REST API连接起来。不知何故,我可以用 GET 做事,但从来没有用POST 和 PUT做。我的代码有什么问题吗?这是我的上传示例:
应用\Http\Controllers\BuildApiController@testBuild:
use...
public function testBuild(Request $request)
{
$build = new PgBuild('myemail@test.us','mypassword');
$title = $request->title;
$file = $request->file;
$method = 'file';
$data = $build->uploadApp($file, $title, $method);
return response()->json($data);
}
应用\PgBuild@uploadApp:
public function uploadApp($file, $title, $createMethod) {
$link = "https://build.phonegap.com/api/v1/apps";
CURL_SETOPT($this->ch, CURLOPT_POST, 1);
CURL_SETOPT($this->ch, CURLOPT_URL, $link);
$post = array(
"data" => array('create_method' => $createMethod, 'title' => $title),
"file" => $file
);
CURL_SETOPT($this->ch, CURLOPT_POSTFIELDS, $post);
$output = curl_exec($this->ch);
$obj = json_decode($output);
if (is_object($obj) && isset($obj->id)) {
return json_encode($obj->id);
} else {
return false;
}
}
谢谢,