ユーザ用ツール

サイト用ツール


サイドバー



最近の更新



Tag Cloud

タグ#
6
10
1
3
1
2
17
7
1
1
6
9
4
1
2
178
1
4
2
7
12
5
1
25
2
3
1
6
1
1
30
1
3
3
1
1
1
1
1
1
13
45
7
9
10
5
10
3
2
2
8
2
2
6
3
1
1
4
7
4
2
2
2
1
7
2
4
1
2
21
2
12
2
3
1
1
2
2
1
1
1
3
2
2
4
2
2
1
1
2
1
1
1
2
1
26
2
1
2
2
2
1
1
2
3
12
4
7
1
1
2
8
1
3
1
1
7
1
1
1
1
1
8
1
4
1
2
1
1
1
3
3
4
1
2
1
1
7
3
1
3
1
1
4
1
2
1
2
6
2
1
3
1
1
3
1
2
1
2
2
2
1
2
3
1
1
3
2
1
3
1
1
3
2
1
1
7
1
3
3
1
1
1
1
5
1
22
2
1
2
1
2
2
3
1
1
1
2
1
2
1
1
1
1
1
1
1

11_php:02_framework:01_laravel:35_laravel_guzzle

35 Laravel Curlの代わりにGuzzleを使う

Crulより簡単で、シンプルに書ける

guzzlehttp/guzzle 6.3.3

インストール

composer require guzzlehttp/guzzle

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Client;

class XmlRpc extends Controller
{
    protected $url;
    protected $user;
    protected $password;
    public function __construct($url='', $user='', $password='')
    {
        $this->url      = $url;
        $this->user     = $user;
        $this->password = $password;
    }
    public function send($method, $params = [])
    {
        $auth = ['login' => $this->user, 'password' => $this->password];
        $params = [$auth, $params];
        $body     = xmlrpc_encode_request($method, $params);
        //print_r($body);
        $response = (new Client)->post($this->url, [
            'body' => $body,
            'auth' => [$this->user, $this->password]
        ]);
        return $response->getBody()->getContents();
    }
}

呼び出し部分

$XmlRcp =  new App\Http\Controllers\XmlRpc($url, $user, $pass);
$XmlRcp->send('partner10.getKeyInfo', 'PLSK.XXXXXXXX.XXXX')
11_php/02_framework/01_laravel/35_laravel_guzzle.txt · 最終更新: 2019/05/25 09:55 by matsui

Yesterday:109 Today:090 Total:13738