hiro
hiro

Reputation: 141

I want to achieve in laravel 5 the same thing as the cakephp of HttpSocket ()

I want to achieve in laravel 5 the same thing as the cakephp of HttpSocket ().

Within your own site, and I want to get the result of the POST to other sites.

CakePhp source code:

$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));

In cakephp, can be achieved by the method described above, but does not know how to do in laravel 5.

Do not anyone understand here?

Upvotes: 1

Views: 263

Answers (1)

Limon Monte
Limon Monte

Reputation: 54409

Guzzle will help you.

  1. Install it via Composer:
    composer require guzzlehttp/guzzle
  1. Alternative of your code using 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
    }

Upvotes: 2

Related Questions