Giter Site home page Giter Site logo

utils-curl's Introduction

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);

utils-curl's People

Contributors

limingxinleo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.