【发布时间】:2014-04-09 10:42:54
【问题描述】:
因变量是:
$randomString 是随机字符串
$num_rows[0] oAuth 2.0 处理后的正确 access_token
请求:
$params = array(
"kind" => "compute#disk",
"zone" => "https://www.googleapis.com/compute/v1/projects/plenary-ability-439/zones/us-central1-a",
"name" => $randomString,
"description" => "any description "
);
$ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $headers = array("Content-Type: application/json" ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); $res = json_decode($result, true);回复:
{
“错误”:{
“错误”:[
{
"domain": "global", "reason": "parseError", "message": "This API does not support parsing form-encoded input."}
],
“代码”:400,
"message": "此 API 不支持解析表单编码输入。"
}
}
$headers = array("Content-Type: application/json" ); 是我目前所知道的并且我已经正确设置了它
*第二件事是:我也试过这个,但我得到了同样的回应*
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $num_rows[0]",
);
【问题讨论】:
标签: php google-app-engine curl google-compute-engine