Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决错误:https://请求需要OpenSSL支持吗?_Php_Openssl_Pear_Mod Ssl - Fatal编程技术网

Php 如何解决错误:https://请求需要OpenSSL支持吗?

Php 如何解决错误:https://请求需要OpenSSL支持吗?,php,openssl,pear,mod-ssl,Php,Openssl,Pear,Mod Ssl,我正在使用,它在本地PC上正常工作,但当我将其上载到服务器时,它给了我以下错误: 邮政999e93717344885fd7c458301a5b00c9应用程序/json周四,9月11日 2014 08:14:20 GMT/TargetError:需要对https的OpenSSL支持:// 请求 域名使用GoDaddy的证书启用了https,出了什么问题 define("SERVER_ACCESS_KEY", "12345678"); define("SERVER_SECR

我正在使用,它在本地PC上正常工作,但当我将其上载到服务器时,它给了我以下错误:

邮政999e93717344885fd7c458301a5b00c9应用程序/json周四,9月11日 2014 08:14:20 GMT/TargetError:需要对https的OpenSSL支持:// 请求

域名使用GoDaddy的证书启用了https,出了什么问题

define("SERVER_ACCESS_KEY", "12345678");
            define("SERVER_SECRET_KEY", "654321");
            define("TARGET_NAME", $campaignname);
            define("IMAGE_LOCATION", $directory . '/dispatcher.' . $path_parts['extension']);

            $this->load->library('Vuforia/PostNewTarget');
示例代码是SignatureBuilder.php:

<?php

/**
 * Copyright (c) 2011-2013 Qualcomm Austria Research Center GmbH. All rights Reserved. Nothing in these materials is an offer to sell any of the components or devices referenced herein. Qualcomm is a trademark of QUALCOMM Incorporated, registered in the United States and other countries.Vuforia is a trademark of QUALCOMM Incorporated. Trademarks of QUALCOMM Incorporated are used with permission.
 * Vuforia SDK is a product of Qualcomm Austria Research Center GmbH. Vuforia Cloud Recognition Service is provided by Qualcomm Technologies, Inc..
 *
 * This Vuforia (TM) sample code provided in source code form (the "Sample Code") is made available to view for reference purposes only. 
 * If you would like to use the Sample Code in your web application, you must first download the Vuforia Software Development Kit and agree to the terms and conditions of the License Agreement for the Vuforia Software Development Kit, which may be found at https://developer.vuforia.com/legal/license. 
 * Any use of the Sample Code is subject in all respects to all of the terms and conditions of the License Agreement for the Vuforia Software Development Kit and the Vuforia Cloud Recognition Service Agreement. 
 * If you do not agree to all the terms and conditions of the License Agreement for the Vuforia Software Development Kit and the Vuforia Cloud Recognition Service Agreement, then you must not retain or in any manner use any of the Sample Code.
 * 
 */

class SignatureBuilder{

    private $contentType = '';
    private $hexDigest = 'd41d8cd95fa11b204e7600998ecf8427e'; // Hex digest of an empty string

    public function tmsSignature( $request , $secret_key ){

        $method = $request->getMethod();
        // The HTTP Header fields are used to authenticate the request
        $requestHeaders = $request->getHeaders();
        // note that header names are converted to lower case
        $dateValue = $requestHeaders['date'];

        $requestPath = $request->getURL()->getPath();

        // Not all requests will define a content-type
        if( isset( $requestHeaders['content-type'] ))
            $this->contentType = $requestHeaders['content-type'];

        if ( $method == 'GET' || $method == 'DELETE' ) {
            // Do nothing because the strings are already set correctly
        } else if ( $method == 'POST' || $method == 'PUT' ) {
            // If this is a POST or PUT the request should have a request body
            $this->hexDigest = md5( $request->getBody() , false );

        } else {
            print("ERROR: Invalid content type passed to Sig Builder");
        }



        $toDigest = $method . "\n" . $this->hexDigest . "\n" . $this->contentType . "\n" . $dateValue . "\n" . $requestPath ;

        echo $toDigest;

        $shaHashed = "";

        try {
            // the SHA1 hash needs to be transformed from hexidecimal to Base64
            $shaHashed = $this->hexToBase64( hash_hmac("sha1", $toDigest , $secret_key) );

        } catch ( Exception $e) {
            $e->getMessage();
        }

        return $shaHashed;  
    }


    private function hexToBase64($hex){

        $return = "";

        foreach(str_split($hex, 2) as $pair){

            $return .= chr(hexdec($pair));

        }

        return base64_encode($return);
    }


}
<?php

require_once 'HTTP/Request2.php';
require_once 'SignatureBuilder.php';

// See the Vuforia Web Services Developer API Specification - https://developer.vuforia.com/resources/dev-guide/retrieving-target-cloud-database
// The PostNewTarget sample demonstrates how to update the attributes of a target using a JSON request body. This example updates the target's metadata.

class PostNewTarget{

    //Server Keys
    private $access_key     = SERVER_ACCESS_KEY;
    private $secret_key     = SERVER_SECRET_KEY;

    //private $targetId         = "eda03583982a41dcbe9ca7f30731b9b1";
    private $url            = "https://vws.vuforia.com";
    private $requestPath    = "/targets";
    private $request;       // the HTTP_Request2 object
    private $jsonRequestObject;

    private $targetName     = TARGET_NAME;
    private $imageLocation  = IMAGE_LOCATION;

    function PostNewTarget(){

        $this->jsonRequestObject = json_encode( array( 'width'=>320.0 , 'name'=>$this->targetName , 'image'=>$this->getImageAsBase64() , 'application_metadata'=>base64_encode("Vuforia test metadata") , 'active_flag'=>1 ) );

        $this->execPostNewTarget();

    }

    function getImageAsBase64(){

        $file = file_get_contents( $this->imageLocation );

        if( $file ){

            $file = base64_encode( $file );
        }

        return $file;

    }

    public function execPostNewTarget(){

        $this->request = new HTTP_Request2();
        $this->request->setMethod( HTTP_Request2::METHOD_POST );
        $this->request->setBody( $this->jsonRequestObject );

        $this->request->setConfig(array(
                'ssl_verify_peer' => false
        ));

        $this->request->setURL( $this->url . $this->requestPath );

        // Define the Date and Authentication headers
        $this->setHeaders();


        try {

            $response = $this->request->send();

            if (200 == $response->getStatus() || 201 == $response->getStatus() ) {
                echo $response->getBody();
            } else {
                echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
                        $response->getReasonPhrase(). ' ' . $response->getBody();
            }
        } catch (HTTP_Request2_Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }


    }

    private function setHeaders(){
        $sb =   new SignatureBuilder();
        $date = new DateTime("now", new DateTimeZone("GMT"));

        // Define the Date field using the proper GMT format
        $this->request->setHeader('Date', $date->format("D, d M Y H:i:s") . " GMT" );

        $this->request->setHeader("Content-Type", "application/json" );
        // Generate the Auth field value by concatenating the public server access key w/ the private query signature for this request
        $this->request->setHeader("Authorization" , "VWS " . $this->access_key . ":" . $sb->tmsSignature( $this->request , $this->secret_key ));

    }
}
我尝试使用此代码查看openssl是否可用:

if (!extension_loaded('openssl')) {
    echo "no openssl extension loaded.";
}
结果是:

没有加载openssl扩展

这是CentOS-PHP版本5.2.17上的版本

错误:https://请求需要OpenSSL支持

如果在您的数据库中找不到
ssl
,则会发生此错误。必须是才能使用


这与Apache的
mod_ssl
或者您的站点是否通过https提供服务无关。它是关于PHP连接到url的
”https://vws.vuforia.com“
执行请求。

如果您使用的是RHEL Linux,例如CentOS
yum安装php openssl openssl

如果您不使用CentOS或RHEL,请评论您使用的内容,以便我可以为您获取正确的命令(如果该命令不起作用)
yum update

您可以在ubuntu上使用apt-get而不是yum来尝试同样的方法,例如
apt-get安装openssl

检查php.ini文件中的
extension=php\u openssl.so
如果它不在那里添加它…

HTTP\u Request2()函数是否使用cURL?有关HTTP\u Request2()的更多信息,请回答“否”。不过,我建议您使用cURL,因为使用它编写代码要容易得多。:)
var_dump(函数_存在('openssl_decrypt'))的结果是什么?这是Windows还是Linux/Unix机器?@lxg它是CentOS Linux,并且var_dump it bool的结果(false)您能告诉我如何安装OpenSSL PHP扩展吗?很高兴知道它是编译的:)是的,它是CentOS我尝试了yum命令,您可以在问题中看到结果。更新以显示如何检查安装到PHP中的OpenSSL。您是否已通过yum安装或编译了您的self?我在php.ini文件的末尾添加了extension=“php_openssl.so”,因为它不在那里,所以重新启动了apache,但没有任何作用。关于yum或Compiled,我不知道,但我没有在这台服务器上安装任何东西。如果您不知道我们无法以这种方式提供帮助,这可能是一个问题。因为如果它是编译的,yum就不能工作,反之亦然,有人知道如何检查它是编译的还是安装的吗?
if (!extension_loaded('openssl')) {
    echo "no openssl extension loaded.";
}