国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php安裝HTTP_Request2及引用介紹(通過HTTP_Request創建微軟人臉識別的群組 為例)

2019-11-11 00:23:05
字體:
來源:轉載
供稿:網友
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 bytesdownloading Net_URL2-2.2.1.tgz ...Starting to download Net_URL2-2.2.1.tgz (20,010 bytes)...done: 20,010 bytesinstall ok: channel://pear.php.net/Net_URL2-2.2.1install 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

Warning: popen() has been disabled for security reasons in OS/Guess.php on line 241PHP Warning:  popen() has been disabled for security reasons in /usr/local/php/lib/php/OS/Guess.php on line 241Warning: fgets() expects parameter 1 to be resource, null given in OS/Guess.php on line 242PHP Warning:  fgets() expects parameter 1 to be resource, null given in /usr/local/php/lib/php/OS/Guess.php on line 242Warning: pclose() expects parameter 1 to be resource, null given in OS/Guess.php on line 251PHP Warning:  pclose() expects parameter 1 to be resource, null given in /usr/local/php/lib/php/OS/Guess.php on line 251Warning: readlink() has been disabled for security reasons in OS/Guess.php on line 257PHP Warning:  readlink() has been disabled for security reasons in /usr/local/php/lib/php/OS/Guess.php on line 257pear/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 bytesdownloading Net_URL2-2.2.1.tgz ...Starting to download Net_URL2-2.2.1.tgz (20,010 bytes)...done: 20,010 bytesinstall ok: channel://pear.php.net/Net_URL2-2.2.1install ok: channel://pear.php.net/HTTP_Request2-2.3.0php中調用實例(直接引用即可)以下為微軟人臉識別API實例,具體需要修改為自己的key密鑰(此處僅僅介紹php引入HTTP_Request方法即直接引入即可)<?php  error_reporting(255);// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)include('HTTP/Request2.php');//add 2017-02-07 subscription key$key1 = 'xxxxxxx'; //在微軟人臉識別處注冊的賬戶對應的face應用api key //add 2017-02-07 personGroupId$group_id = 'school_1';$request = new Http_Request2("https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/{$group_id}");$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]);########################################################################################$headers = array(    // Request headers    'Content-Type' => 'application/json',    'Ocp-Apim-Subscription-Key' => $key1,);$request->setHeader($headers);$parameters = array(    // Request parameters 'personGroupId'=>$group_id);$url->setQueryVariables($parameters);$request->setMethod(HTTP_Request2::METHOD_PUT);// Request body// add body$body = '{"name":"group1", "userData":"group1 userData test"}';$request->setBody("{$body}");try{    $response = $request->send();    echo $response->getBody();}catch (HttpException $ex){    echo $ex;}?>以下是通過HTTP_Request創建人臉識別群組操作成功與否返回的提示信息(出現如下狀態信息,就說明HTTP_Request成功請求了人臉識別接口,到此HTTP_REQUEST2的使用介紹完畢)

Response 200

A successful call returns an empty response body.

Response 400

Error code and message returned in JSON:

Error CodeError Message Description
BadArgument'name' is too long.
BadArgument'userData' is too long.
BadArgumentBad and unrecognizable JSON body.
BadArgumentPerson group ID is invalid. Valid format should be a string composed by numbers, English letters in lower case, '-', '_', and no longer than 64 characters.

application/json
{    "error":{        "code":"BadArgument",        "message":"'name' is too long."    }}                						                    						                    						                    						                    						                                                

Response 401

Error code and message returned in JSON:

Error CodeError Message Description
UnspecifiedInvalid subscription Key or user/plan is blocked.

application/json
{    "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

application/json
{    "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 CodeError Message Description
PersonGroupExistsPerson group already exists.
ConcurrentOperationConflictConcurrent operation conflict on resource.

application/json
{    "error":{        "code":"PersonGroupExists",        "message":"Person group 'sample_group' already exists."    }}                						                    						                    						                    						                    						                                                

Response 415

Unsupported media type error. Only "application/json" is valid for this API.

application/json
{    "error":{        "code":"BadArgument",        "message":"Invalid Media Type"    }}                						                    						                    						                    						                    						                                                

Response 429

application/json
{    "error":{        "statusCode": 429,        "message": "Rate limit is exceeded. Try again in 26 seconds."    }}                						                    						                    						                    						                    						                        

這里僅僅對HTTP_Request的安裝和引用做下簡單介紹,詳細人臉識別部分會在后期出專門的技術文檔教材出來,敬請關注...


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 闸北区| 高清| 中牟县| 金阳县| 泰和县| 奈曼旗| 张家港市| 周口市| 通化县| 晋中市| 永和县| 安国市| 山阳县| 门头沟区| 霞浦县| 澄城县| 望都县| 涿鹿县| 女性| 深州市| 祥云县| 凤山县| 巫溪县| 平舆县| 兴隆县| 会同县| 常熟市| 敦化市| 沛县| 丹寨县| 九台市| 水富县| 彭阳县| 金寨县| 华坪县| 开平市| 大安市| 贡嘎县| 繁昌县| 石河子市| 大埔县|