使用原始数据发送请求
Sending request with guzzle with raw data
我想发送一个像这样的 guzzle 请求。
Post man request
事实是,我总是得到
Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: POST http://localhost:8080/project/user/login
resulted in a 400 Bad Request
下面是创建和发送请求的代码部分:
if (isset ($_REQUEST['username']) && isset($_REQUEST['password'])){
require '../php/vendor/autoload.php';
$myClient = new GuzzleHttp\Client();
$request = $myClient->post("http://localhost:8080/project/user/login");
$request->setBody($_REQUEST['username']. ',' . $_REQUEST['password']);
$feed_response = $request->send();
我已经阅读了 guzzle 的大部分手册,但对我毫无帮助。
您使用的是哪个版本的 Guzzle。使用最新版本。在最新版本的 Guzzle 中,http POST 请求发送为:
$client->request('POST', '/post', [
'form_params' => [
'foo' => 'bar',
'baz' => ['hi', 'there!']
]
]);
看到这个link:http://docs.guzzlephp.org/en/latest/request-options.html?#form-params
我想发送一个像这样的 guzzle 请求。
Post man request
事实是,我总是得到
Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error:
POST http://localhost:8080/project/user/login
resulted in a400 Bad Request
下面是创建和发送请求的代码部分:
if (isset ($_REQUEST['username']) && isset($_REQUEST['password'])){
require '../php/vendor/autoload.php';
$myClient = new GuzzleHttp\Client();
$request = $myClient->post("http://localhost:8080/project/user/login");
$request->setBody($_REQUEST['username']. ',' . $_REQUEST['password']);
$feed_response = $request->send();
我已经阅读了 guzzle 的大部分手册,但对我毫无帮助。
您使用的是哪个版本的 Guzzle。使用最新版本。在最新版本的 Guzzle 中,http POST 请求发送为:
$client->request('POST', '/post', [
'form_params' => [
'foo' => 'bar',
'baz' => ['hi', 'there!']
]
]);
看到这个link:http://docs.guzzlephp.org/en/latest/request-options.html?#form-params