2017-04-03 79 views
1

我想適合CRM REST API連接使用狂飲如何連接使用狂飲

$res = $client->request('GET','http://crm.demo.com/service/v4_1/rest.php/login', [ "auth" => [ 'myadmin', md5('mypswd') ]]); 

    print_r($res); 

我得到的結果適合CRM REST API是這個

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來實現這一點。

回答

0

首先,問題是什麼?你的代碼是正確的,你會得到迴應。

如果你想探索響應體,只需要做(string) $res->getBody()$res->getBody()->getContents()(正文是一個流,因爲你可以在你的轉儲,所以要得到它作爲一個字符串,你必須做更多的動作)。

順便說一句,您嘗試訪問CloudFlare下的網站,通常這是不可能的,因爲CloudFlare會拒絕機器人。嘗試獲取不同的入口點(不在CloudFlare保護下)。

+0

謝謝@Alexey Shockov指出這個cloudflare問題。我對這個迴應有點困惑。現在我得到了它的工作 – AVM