Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php HTTP请求失败!HTTP/1.1400错误请求_Php_Google App Engine_Jira_Jira Rest Api_Http Streaming - Fatal编程技术网

Php HTTP请求失败!HTTP/1.1400错误请求

Php HTTP请求失败!HTTP/1.1400错误请求,php,google-app-engine,jira,jira-rest-api,http-streaming,Php,Google App Engine,Jira,Jira Rest Api,Http Streaming,我试图在吉拉制造一个问题 我能够发出带有正确响应的GET请求,但是当我发出POST请求时,问题就出现了 <?php $userName ='xxxxxxxxxxxxxxxx'; $password ='xxxxxxxxxxxx'; $data = ['fields' => ['projects'=>['key'=>'ABC'],'summary'=>'abc','description'=>'abc','issuetype'=>['name'=>

我试图在吉拉制造一个问题

我能够发出带有正确响应的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;
有人能帮我吗?谢谢

附言

我不想使用curl代替http流,因为googleappengine不支持curl。

生成一个url编码的字符串。但是,API需要JSON。你应该改用

更改:

$data = http_build_query($data);
致:


虽然这可能不是您唯一的问题,但这肯定是一个会导致400个错误请求的问题。

您的代码中是否有输入错误

$data=array('fields' => array ('project' => array ('key' => 'WOIS',),'summary' => 'ABC','description' => 'ABC','issuetype' => array ('name' => 'Task',),),); 
vs


第一行显示
project
,第二行显示
projects

您正在发送一个查询字符串,但声称发送JSON。这可能是你的第一个问题。@JasonMcCreary这里是上面使用curl的例子,你能建议应该是什么帖子url吗?谢谢Jason,你是对的,使用json_encode()解决了这个问题。我还有一个小问题,与$data=array('fields'=>array('project'=>array('key'=>'WOIS',),'summary'=>'ABC','description'=>'ABC','issuetype'=>array('name'=>'Task',),)有什么区别;和$data=['fields'=>['projects'=>['key'=>'WOIS']、'summary'=>'adfsdf'、'description'=>'adfefsa'、'issuetype'=>['name'=>'Task']];因为如果我使用第二个$data,它就无法识别project字段。在我看来,这两种表示都是正确的。谢谢,很好。我会在另一个问题中问这个问题,这样就更清楚了。欢迎来到StackOverflow。这个问题已经有了一个公认的答案,问题不是打字错误。。。
$data = json_encode($data);
$data=array('fields' => array ('project' => array ('key' => 'WOIS',),'summary' => 'ABC','description' => 'ABC','issuetype' => array ('name' => 'Task',),),); 
$data = ['fields' => ['projects'=>['key'=>'WOIS'],'summary'=>'adfsdf','descriptio‌​n'=>'adfefsa','issue‌​type'=>['name'=>'Tas‌​k']]];