如何使用 Guzzle 连接到套件 CRM REST API
How to connect to suite CRM REST API using Guzzle
我正在尝试使用 Guzzle
连接到套件 CRM REST API
$res = $client->request('GET','http://crm.demo.com/service/v4_1/rest.php/login', [ "auth" => [ 'myadmin', md5('mypswd') ]]);
print_r($res);
我得到的结果是这样的
GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
[statusCode:GuzzleHttp\Psr7\Response:private] => 200
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Date] => Array
(
[0] => Mon, 03 Apr 2017 06:26:17 GMT
)
[Content-Type] => Array
(
[0] => text/html; charset=UTF-8
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Connection] => Array
(
[0] => keep-alive
)
[Set-Cookie] => Array
(
[0] => __cfduid=daace974785b1e202e7535232346958d111491200776; expires=Tue, 03-Apr-18 06:26:16 GMT; path=/; domain=.demo.com; HttpOnly
)
[X-Powered-By] => Array
(
[0] => PHP/5.4.16
)
[X-Varnish] => Array
(
[0] => 2592144
)
[Age] => Array
(
[0] => 0
)
[Via] => Array
(
[0] => 1.1 varnish-v4
)
[Server] => Array
(
[0] => cloudflare-nginx
)
[CF-RAY] => Array
(
[0] => 3499f497d6bd17a4-SIN
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[date] => Date
[content-type] => Content-Type
[transfer-encoding] => Transfer-Encoding
[connection] => Connection
[set-cookie] => Set-Cookie
[x-powered-by] => X-Powered-By
[x-varnish] => X-Varnish
[age] => Age
[via] => Via
[server] => Server
[cf-ray] => CF-RAY
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #73
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
它显示请求成功,但我没有得到结果。真的可以使用 Guzzle 连接它吗?还有其他方法可以传递登录参数吗?
我正在使用 CodeIgniter 3 和 Guzzle 来实现这一点。
首先,问题是什么?你的代码是正确的,你得到了回应。
如果您想探索响应主体,只需执行 (string) $res->getBody()
或 $res->getBody()->getContents()
(主体是一个流,就像您在转储中一样,所以要将其作为字符串获取执行其他操作)。
顺便说一句,您正在尝试访问 CloudFlare 下的站点,通常这是不可能的,因为 CloudFlare 拒绝机器人。尝试获取不同的入口点(不受 CloudFlare 保护)。
我正在尝试使用 Guzzle
连接到套件 CRM REST API $res = $client->request('GET','http://crm.demo.com/service/v4_1/rest.php/login', [ "auth" => [ 'myadmin', md5('mypswd') ]]);
print_r($res);
我得到的结果是这样的
GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
[statusCode:GuzzleHttp\Psr7\Response:private] => 200
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Date] => Array
(
[0] => Mon, 03 Apr 2017 06:26:17 GMT
)
[Content-Type] => Array
(
[0] => text/html; charset=UTF-8
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Connection] => Array
(
[0] => keep-alive
)
[Set-Cookie] => Array
(
[0] => __cfduid=daace974785b1e202e7535232346958d111491200776; expires=Tue, 03-Apr-18 06:26:16 GMT; path=/; domain=.demo.com; HttpOnly
)
[X-Powered-By] => Array
(
[0] => PHP/5.4.16
)
[X-Varnish] => Array
(
[0] => 2592144
)
[Age] => Array
(
[0] => 0
)
[Via] => Array
(
[0] => 1.1 varnish-v4
)
[Server] => Array
(
[0] => cloudflare-nginx
)
[CF-RAY] => Array
(
[0] => 3499f497d6bd17a4-SIN
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[date] => Date
[content-type] => Content-Type
[transfer-encoding] => Transfer-Encoding
[connection] => Connection
[set-cookie] => Set-Cookie
[x-powered-by] => X-Powered-By
[x-varnish] => X-Varnish
[age] => Age
[via] => Via
[server] => Server
[cf-ray] => CF-RAY
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #73
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
它显示请求成功,但我没有得到结果。真的可以使用 Guzzle 连接它吗?还有其他方法可以传递登录参数吗?
我正在使用 CodeIgniter 3 和 Guzzle 来实现这一点。
首先,问题是什么?你的代码是正确的,你得到了回应。
如果您想探索响应主体,只需执行 (string) $res->getBody()
或 $res->getBody()->getContents()
(主体是一个流,就像您在转储中一样,所以要将其作为字符串获取执行其他操作)。
顺便说一句,您正在尝试访问 CloudFlare 下的站点,通常这是不可能的,因为 CloudFlare 拒绝机器人。尝试获取不同的入口点(不受 CloudFlare 保护)。