PHP code example of ailiangkuai / http-client

1. Go to this page and download the library: Download ailiangkuai/http-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ailiangkuai / http-client example snippets



use Ym\http\request\HttpClient;

/*
 * 请求的url:http://www.test.com/server/test/index?a=1
 * 请求方法:post
 * 请求$_POST参数 ['a'=>1]
 * 返回array
 * */
$response = HttpClient::post('http://www.test.com' . '/server/test/index')
->setFormData(['aaa'=>'post'])  //设置body实体并设置content-type为application/x-www-form-urlencoded
->setQuery(['a' => 1])  //设置url后面加到参数
->send()
->getJsonData();//解析json字符串




 
use Ym\http\request\HttpClient;
/*
 * 请求的url:http://www.test.com/server/test/xml?a=1
 * 请求方法:get
 * 返回array
 * */
$response = HttpClient::get('http://www.test.com' . '/server/test/xml')
->setQuery(['a' => 1])  //设置url后面加到参数
->send()->getXmlData();