Easy Install
pear install HTTP_Request2
Pyrus Install
php pyrus.phar install pear/HTTP_Request2
出现下列信息则表示安装成功
pear/HTTP_Request2 can optionally use PHP extension "fileinfo"
downloading HTTP_Request2-2.3.0.tgz ...
Starting to download HTTP_Request2-2.3.0.tgz (119,717 bytes)
..........................done: 119,717 bytes
downloading Net_URL2-2.2.1.tgz ...
Starting to download Net_URL2-2.2.1.tgz (20,010 bytes)
...done: 20,010 bytes
install ok: channel://pear.php.net/Net_URL2-2.2.1
install ok: channel://pear.php.net/HTTP_Request2-2.3.0(摘取天上星:分享每个人都能看懂的实例)
如果出现类似如下红色部分信息,则需要修改php.ini配置文件打开被禁用的相应函数(去掉disable_functions中的popen,readlink)即可,总之提示那个函数错误开启那个函授即可!
disable_functions=eval,passthru,exec,system,chroot,chgrp,chown,shell_exec,ini_alter,ini_restore,dl,openlog,syslog,symlink,popepassthru,fsocket,stream_socket_server,readlink,popen
PHP Warning: popen() has been disabled for security reasons in /usr/local/php/lib/php/OS/Guess.php on line 241
PHP Warning: fgets() expects parameter 1 to be resource, null given in /usr/local/php/lib/php/OS/Guess.php on line 242
PHP Warning: pclose() expects parameter 1 to be resource, null given in /usr/local/php/lib/php/OS/Guess.php on line 251
PHP Warning: readlink() has been disabled for security reasons in /usr/local/php/lib/php/OS/Guess.php on line 257
pear/HTTP_Request2 can optionally use PHP extension "fileinfo"
downloading HTTP_Request2-2.3.0.tgz ...
Starting to download HTTP_Request2-2.3.0.tgz (119,717 bytes)
..........................done: 119,717 bytes
downloading Net_URL2-2.2.1.tgz ...
Starting to download Net_URL2-2.2.1.tgz (20,010 bytes)
...done: 20,010 bytes
install ok: channel://pear.php.net/Net_URL2-2.2.1
install ok: channel://pear.php.net/HTTP_Request2-2.3.0
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
include('HTTP/Request2.php');
$key1 = 'xxxxxxx'; //在微软人脸识别处注册的账户对应的face应用api key
//add 2017-02-07 personGroupId
$group_id = 'school_1';
$url = $request->getUrl();
# 记得一定要关闭证书验证,否则会出现如下证书验证失败的错误提示
/*
Fatal error: Uncaught
HTTP_Request2_ConnectionException: Unable to connect to tls://westus.api.cognitive.microsoft.com:443.
Error: stream_socket_client(): unable to connect to tls://westus.api.cognitive.microsoft.com:443 (Unknown error)
stream_socket_client(): Failed to enable crypto stream_socket_client(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:
certificate verify failed in /usr/local/php/lib/php/HTTP/Request2/Adapter/Socket.php on line 332
*/
########################################################################################
$request->setConfig(['ssl_verify_peer'=>FALSE,'ssl_verify_host'=>FALSE]);
########################################################################################
// Request headers
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => $key1,
);
// Request parameters
'personGroupId'=>$group_id
);
// add body
$body = '{"name":"group1", "userData":"group1 userData test"}';
$request->setBody("{$body}");
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
Response 200
A successful call returns an empty response body.
Response 400
Error code and message returned in JSON:
Error Code | Error Message Description |
---|---|
BadArgument | 'name' is too long. |
BadArgument | 'userData' is too long. |
BadArgument | Bad and unrecognizable JSON body. |
BadArgument | Person group ID is invalid. Valid format should be a string composed by numbers, English letters in lower case, '-', '_', and no longer than 64 characters. |
{
"error":{
"code":"BadArgument",
"message":"'name' is too long."
}
}
Response 401
Error code and message returned in JSON:
Error Code | Error Message Description |
---|---|
Unspecified | Invalid subscription Key or user/plan is blocked. |
{
"error":{
"code": "Unspecified",
"message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
}
}
Response 403
{
"error":{
"statusCode": 403,
"message": "Out of call volume quota. Quota will be replenished in 2.12 days."
}
}
Response 409
Error code and message returned in JSON:
Error Code | Error Message Description |
---|---|
PersonGroupExists | Person group already exists. |
ConcurrentOperationConflict | Concurrent operation conflict on resource. |
{
"error":{
"code":"PersonGroupExists",
"message":"Person group 'sample_group' already exists."
}
}
Response 415
Unsupported media type error. Only "application/json" is valid for this API.
{
"error":{
"code":"BadArgument",
"message":"Invalid Media Type"
}
}
Response 429
{
"error":{
"statusCode": 429,
"message": "Rate limit is exceeded. Try again in 26 seconds."
}
}
这里仅仅对HTTP_Request的安装和引用做下简单介绍,详细人脸识别部分会在后期出专门的技术文档教材出来,敬请关注...