Closed lyxyhghjkl closed 3 years ago
use Swoole\Runtime;
use Swoole\Coroutine\Http\Client;
use function Swoole\Coroutine\run;
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
run(function () {
$host = "runtime.lex.us-east-1.amazonaws.com";
$port = "443";
$ssl = "1";
$method = "POST";
$content = file_get_contents('/www/wwwroot/aws.vm.com/text2audio.au');
$headers = ["Host"=>"runtime.lex.us-east-1.amazonaws.com",
"Accept"=>"text/plain; charset=utf-8",
"Content-Type"=>"audio/l16; rate=16000; channels=1",
"transfer-encoding"=>"chunked",
"aws-sdk-invocation-id"=>"854b94785f7c6f14",
"aws-sdk-retry"=>"0/0",
"X-Amz-Date"=>"20210424T100341Z",
"X-Amz-Content-Sha256"=>"UNSIGNED-PAYLOAD",
"Authorization"=>"AWS4-HMAC-SHA256 Credential=AKIA57DAQR4NNW/20210424/us-east-1/lex/aws4_request, SignedHeaders=host;transfer-encoding;x-amz-content-sha256;x-amz-date, Signature=9d00499c64431deddbead165ebd44de9e69aaac3ec3ab9dc971dd24922d7cb9e",
"User-Agent"=>"aws-sdk-php/3.178.8 OS/Linux/3.10.0-1160.15.2.el7.x86_64 GuzzleHttp/7"
];
$path = "/bot/e/alias/virgi/user/39dd-ac73-7620-76208970359b/content";
$settings = ["ssl_allow_self_signed"=>false];
$httpClient = new Client($host, $port, $ssl);
$httpClient->setMethod($method);
$httpClient->setData($content);
$httpClient->setHeaders($headers);
$httpClient->set($settings);
$status = $httpClient->execute($path);
});
<?php
$fi = file_get_contents("test");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://runtime.lex.us-east-1.amazonaws.com/bot/emo/alias/virgi/user39dd-ac73-7620-76208970359b/content',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $fi,
CURLOPT_SSL_VERIFYPEER =>'false',
CURLOPT_SSL_VERIFYHOST =>'false',
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => array(
'Host: runtime.lex.us-east-1.amazonaws.com',
'Accept: text/plain; charset=utf-8',
'Content-Type: audio/l16; rate=16000; channels=1',
'transfer-encoding: chunked',
'aws-sdk-invocation-id: 854b94785f7c6f14',
'aws-sdk-retry: 0/0',
'X-Amz-Date: 20210424T100341Z',
'X-Amz-Content-Sha256: UNSIGNED-PAYLOAD',
'Authorization: AWS4-HMAC-SHA256 Credential=AKIA57DAQURTKRER4NNW/20210424/us-east-1/lex/aws4_request, SignedHeaders=host;transfer-encoding;x-amz-content-sha256;x-amz-date, Signature=9d00499c64431deddbead165ebd9e69aaac3ec3ab9dc971dd24922d7cb9e',
'User-Agent: aws-sdk-php/3.178.8 OS/Linux/3.10.0-1160.15.2.el7.x86_64 GuzzleHttp/7'
),
));
$response = curl_exec($curl);
curl_close($curl);
curl的是正常的
@lyxyhghjkl 你的例子缺少必要的文件,无法正常运行,请添加微信 rangohan
,单独发给我一下
Swoole\Coroutine\Http\Client
不支持 "transfer-encoding"=>"chunked",
这会导致aws
服务器无法解析 HTTP 请求,直接 reset 连接,请去掉 "transfer-encoding"=>"chunked"
头设置,或者改成使用 curl native hook
模式发起请求
errcode 不是9 ssl rest ,就是 104 Connection reset by peer 而不走协程直接用curlpost 或者guzzle post 都不会报错 我开了ssl_allow_self_signed =false 好像没有效果