1. Go to this page and download the library: Download hehex/hehep-hclient 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/ */
use hclient\Client;
$hclient = new Client();
$hclient->site('baidu')->get('system/site/siteInit');
$hclient->site('baidu')->post('system/site/siteInit',['id'=>1]);
$hclient->site('baidu')->getResult('system/site/siteInit');
$hclient->site('baidu')->postResult('system/site/siteInit',['id'=>1]);
use hclient\Client;
$hclient = new Client();
$response = $hclient->site('baidu')
->uri('system/site/siteInit',['id'=>1])
->send();
use hclient\Client;
$hclient = new Client();
$response = $hclient->site()
->setBaseUrl('https://sports.sina.com.cn/')
->uri('system/site/siteInit',['id'=>1])
->send();
namespace hclient\formatters;
use hclient\base\Request;
class JsonFormatter implements FormatterInterface
{
public $encodeOptions = 0;
// 实现此方法
public function format(Request $request)
{
$request->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
$request->setContent(json_encode($request->getData(), $this->encodeOptions));
return $request;
}
}
namespace hclient\formatters;
use hclient\base\Response;
/**
* Response json 反序列化
*<B>说明:</B>
*<pre>
* 略
*</pre>
*/
class JsonParser implements ParserInterface
{
// 实现此方法
public function parse(Response $response)
{
// 错误码
$decode = json_decode((string) $response->getContent(), true);
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$response->addError('json decode error:#The maximum stack depth has been exceeded.');
break;
case JSON_ERROR_CTRL_CHAR:
$response->addError('json decode error:#Control character error, possibly incorrectly encoded.');
break;
case JSON_ERROR_SYNTAX:
$response->addError('json decode error:#Syntax error.');
break;
case JSON_ERROR_STATE_MISMATCH:
$response->addError('json decode error:#Invalid or malformed JSON.');
break;
case JSON_ERROR_UTF8:
$response->addError('json decode error:#Malformed UTF-8 characters, possibly incorrectly encoded.');
break;
default:
$response->addError('json decode error:#Unknown JSON decoding error.');
break;
}
return $decode;
}
}
namespace hclient\transports;
use Exception;
class StreamTransport extends Transport
{
// 实现此方法
public function send($request)
{
// 发送单个请求
return $request;
}
// 扩展此方法
public function batchSend($requests)
{
// 批量发送多个请求
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.