Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/limingxinleo/utils-curl
Curl 类
https://github.com/limingxinleo/utils-curl
curl php
Last synced: about 2 months ago
JSON representation
Curl 类
- Host: GitHub
- URL: https://github.com/limingxinleo/utils-curl
- Owner: limingxinleo
- Created: 2017-06-09T03:52:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-11T14:34:51.000Z (over 7 years ago)
- Last Synced: 2024-11-14T16:07:19.943Z (about 2 months ago)
- Topics: curl, php
- Language: PHP
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Curl 类
### 安装
~~~
composer require limingxinleo/utils-curl
~~~### 使用方法
* GET 方法
~~~
require_once 'vendor/autoload.php';use limx\curl\Application;
$curl = new Application();
// 可以在opt中设置header
$curl->opt->setHeader("Opt-Test", 'Opt-Value');$url = 'https://demo.phalcon.lmx0536.cn/test/api/api?get=simpleGet';
$params = [
'get1' => 1,
'get2' => 2,
];
// 在Client中设置Header
$header = [
'Client-Test' => 'Client-Value'
];
$result = $curl->client->setHeaders($header)->get($url, $params)->getJsonContent();
print_r($result);~~~
* Post
~~~
require_once 'vendor/autoload.php';use limx\curl\Application;
$curl = new Application();
$url = 'https://demo.phalcon.lmx0536.cn/test/api/api?get=simpleGet';
$params = [
'get1' => 1,
'get2' => 2,
];
$headers = [
'Header-Test' => '1',
];// Content-Type=application/x-www-form-urlencoded
$result = $curl->client->setHeaders($headers)->post($url, $params)->getJsonContent();
print_r($result);// Content-Type=json
$result = $curl->client->setHeaders($headers)->format('json')->post($url, $params)->getJsonContent();
print_r($result);~~~