【问题标题】:HTTP/Request2.php not found even after installing HTTP_Request2即使在安装 HTTP_Request2 后也找不到 HTTP/Request2.php
【发布时间】: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-&gt;setConfig("ssl_verify_peer", false); (2) 正文需要正确的 JSON:$request-&gt;setBody("{\"url\":\"https://scontent....\"}");

标签: php http pear microsoft-cognitive


【解决方案1】:

您的包含路径设置不正确。

您应该需要修改包含路径。如果这样做,请将您的更改追加到现有的包含路径中并且不要覆盖它。

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 2014-06-10
    • 2021-12-14
    相关资源
    最近更新 更多