【发布时间】:2015-03-12 15:35:34
【问题描述】:
这个 api 调用使用 Postman(一个 REST 客户端)可以正常工作, 但是在我的 GAE 应用程序中向服务器发出请求时,我目前收到以下错误:
HTTP 请求失败!在第 26 行的 C:\Projects\app\file.php 中
打开流失败:HTTP 请求失败!第 26 行 C:\Projects\app\file.php 中的 HTTP/1.0 400 错误请求
这是我的应用程序中的代码,它调用了 rest api 方法 /exampleMethod
$dataraw = [
'email' => 'email@ex.com',
'first_name' => 'firstname',
'last_name' => 'lastname',
'fEmail' => 'email@ex.com',
'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。
【问题讨论】:
-
您确定 PUT 请求不到 30 秒?
-
是的,在 Postman 中不到 2 秒。
标签: php rest google-app-engine put