Moh*_*uib 4 post codeigniter get http guzzle
我正在 Codeigniter 3.2 上创建一个 Web 应用程序,它与 Facebook Graph API 一起使用。为了发出 GET 和 POST HTTP 请求,我需要一个用于 Codeigniter 的 curl 库。我找到了 Guzzle,但我不知道如何在 Codeigniter 上使用 Guzzle。
小智 6
检查此链接:
https://github.com/rohitbh09/codeigniter-guzzle
$this->load->library('guzzle');
# guzzle client define
$client = new GuzzleHttp\Client();
#This url define speific Target for guzzle
$url = 'http://www.google.com';
#guzzle
try {
# guzzle post request example with form parameter
$response = $client->request( 'POST',
$url,
[ 'form_params'
=> [ 'processId' => '2' ]
]
);
#guzzle repose for future use
echo $response->getStatusCode(); // 200
echo $response->getReasonPhrase(); // OK
echo $response->getProtocolVersion(); // 1.1
echo $response->getBody();
} catch (GuzzleHttp\Exception\BadResponseException $e) {
#guzzle repose for future use
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
print_r($responseBodyAsString);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16055 次 |
| 最近记录: |