【发布时间】:2016-09-07 15:16:18
【问题描述】:
我在 NameCheap 上使用共享托管计划。对于 Microsoft Cognitive API,我需要使用 HTTP/Request2.php 文件,因此我安装了 2 个 PEAR 包
- HTTP_Request2
- Net_URL2
我仍然收到错误无法打开流:没有这样的文件或目录
在 cPanel 中显示
管理员已启用从“/home/XYZ/php”自动加载“PHP 扩展和应用程序包”。
您无需修改脚本。
仍然显示错误。如何解决问题?
添加PHP代码
<?php
ini_set('include_path', '/home/XXXXXX/php');
require_once ' /home/XXXXXXX/php/HTTP/Request2.php';
$request = new Http_Request2('https://api.projectoxford.ai/face/v1.0/detect');
$url = $request->getUrl();
$headers = array(
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => '********************',
);
$request->setHeader($headers);
$parameters = array(
'returnFaceId' => 'false',
'returnFaceLandmarks' => 'false',
'returnFaceAttributes' => 'age',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setBody("url:https://scontent.fbom1-2.fna.fbcdn.net/v/t1.0-9/10404393_1605697742978971_873608472502612270_n.jpg?oh=e10bf5b81b1f945594a1e0298cbae1e6&oe=583A5A85");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
【问题讨论】:
-
你能提供一些代码和完整的错误信息吗?
-
@Devon 立即查看
-
与您的核心问题无关,但在理顺 Request2 问题后,您需要解决一些问题。 (1) SSL 配置需要调整:
$request->setConfig("ssl_verify_peer", false);(2) 正文需要正确的 JSON:$request->setBody("{\"url\":\"https://scontent....\"}");
标签: php http pear microsoft-cognitive