9. 使用https

NOS PHP SDK支持使用https的方式调用相关的接口,以保证安全性

9.1. php 使用openssl相关配置

php curl使用ssl需要安装和配置php_openssl的扩展,具体的安装及配置方式请查看 php document openssl安装/配置

9.2. 使用https

只需要将endpoint从http://nos-eastchina1.126.net修改为https://nos-eastchina1.126.net就可正常使用https的方式访问NOS

9.3. 实例

以下代码实现以https的方式上传本地文件,具体实现如下:

<?php
//以https方式上传指定的本地文件内容

use NOS\NosClient;

$nosClient = new NosClient("xxxxx", "xxxxx", "https://nos-eastchina1.126.net");
$bucket = "test-https-bucket"
$object = "nos-php-sdk-test/upload-test-object-name.txt";
$filePath = __FILE__;
try{
    $nosClient->uploadFile($bucket, $object, $filePath);
} catch(NosException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");