我想在laravel 5中实现与HttpSocket()的cakephp相同的东西。
在您自己的网站中,我希望将POST的结果发送到其他网站。
CakePhp源代码:
$socket = new HttpSocket();
$url = 'http://other-site.com/pages/';
$option['login'] = array('id'=>'abc','pass'=>'xxxxxxx');
$option['data']['hasOne'] = array('startDate' => '2015-04-16', 'endDate' => '2015-04-17');
$list = unserialize($socket->post($url,$option));
在cakephp中,可以通过上述方法实现,但不知道如何在laravel 5中完成。
这里没有人理解吗?
答案 0 :(得分:2)
Guzzle会帮助你。
composer require guzzlehttp/guzzle
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post(
'http://other-site.com/pages/',
[
'login' => ['id' => 'abc', 'pass' => 'xxxxxxx'],
'data' => ['hasOne' => ['startDate' => '2015-04-16', 'endDate' => '2015-04-17']]
]
);
if ($response->getStatusCode() === 200) {
$list = unserialize($response->getBody());
} else {
// handle error
}