【发布时间】:2015-04-10 18:02:47
【问题描述】:
我正在尝试在 Jira 中创建问题。
我能够发出正确响应的 GET 请求,但是当我发出 POST 请求时出现问题。这是代码。
<?php
$userName ='xxxxxxxxxxxxxxxx';
$password ='xxxxxxxxxxxx';
$data = ['fields' => ['projects'=>['key'=>'ABC'],'summary'=>'abc','description'=>'abc','issuetype'=>['name'=>'Task']]];
$data = http_build_query($data);
$context =
array("http"=>
array(
"method" => "POST",
"header" => "Authorization: Basic " . base64_encode($userName.':'.$password) . "\r\n".
'Accept: application/json'."\r\n".
"Content-Length: ".strlen($data)."\r\n".
'Content-Type: application/json'."\r\n",
'content' => $data,
'verify_peer'=>false,
'verify_peer_name'=>false,
)
);
$context = stream_context_create($context);
$result = file_get_contents("https://xxxxx.atlassian.net/rest/api/2/issue/", false, $context);
echo "The result is ", $result;
?>
我收到以下错误:
Warning:file_get_contents(https://xxxxx.atlassian.net/rest/api/2/issue/):
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in
/var/www/html/test/new.php on line 27
谁能帮帮我?谢谢
附言
我不想使用 curl 作为 http-streams 的替代品,因为谷歌应用引擎不支持 curl。
【问题讨论】:
-
您正在发送查询字符串,但声称要发送 JSON。这可能是您的第一个问题。
-
@JasonMcCreary 这里是上面使用 curl 的示例,developer.atlassian.com/jiradev/api-reference/jira-rest-apis 你能建议帖子网址应该是什么吗?
标签: php google-app-engine jira jira-rest-api http-streaming