使用Postman(REST客户端)可以很好地进行此api调用,但是在我的GAE应用程序中的服务器上发出请求时,当前出现以下错误:
HTTP请求失败!在第26行的C:\ Projects \ app \ file.php中
无法打开流:HTTP请求失败!第26行的C:\ Projects \ app \ file.php中的HTTP / 1.0 400错误请求
这是我的应用程序中的代码,该代码调用其余的api方法/ exampleMethod
$dataraw = [
'email' => '[email protected]',
'first_name' => 'firstname',
'last_name' => 'lastname',
'fEmail' => '[email protected]',
'message' => 'test'
];
$data = http_build_query ( $dataraw );
$context = [
'http' => [
'method' => 'PUT',
'header' => "Authorization: apikeystring\r\n" . "Content-Length: " . strlen($data) . "\r\n" . "Content-Type: application/json\r\n",
'content' => $data,
'proxy' => 'tcp://euproxy.example.com:0000'
]
];
$context = stream_context_create ( $context );
$result = file_get_contents ( $GLOBALS ['REST_API_URL'] . '/exampleMethod', false, $context );
在该应用程序中,我已经成功地将file_get_contents用于GET请求,但是通过此PUT请求,我收到了一个400错误的请求,该请求不是来自Rest Api。
将mb_strlen(serialize($ dataraw),'8bit')更改为strlen($ data)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句