gpt4 book ai didi

php - socket.io 中的 app.post ('/posts' 带有 https

转载 作者:太空宇宙 更新时间:2023-11-04 02:19:00 25 4
gpt4 key购买 nike

我正在尝试设置以下代码以通过 https 协议(protocol)接受来自 php 和 Nodejs 的curl 请求。 我知道代码在nodejs端使用http,但是一旦我将协议(protocol)切换到https“RECEIVED”就不会在nodejs中记录。这是:

app.post('/posts', function(req, res){

console.log("RECEIVED");

});

总结:

  • “received”是用nodejs以http模式记录的
  • “received”在 https 模式下使用 Nodejs 记录
  • $curl_url(在 HTTP 中)' http://127.0.0.1 :'.$socket_port.'/posts';
  • $curl_url(在 HTTPS 中)' https://127.0.0.1 :'.$socket_port.'/posts';

有人对此有任何想法吗?这是我的 curl 函数:

    $ch = curl_init();

$ch_options = array("Expect:");

if($encode_json){
array_push($ch_options,"Content-type: application/json");
$data = json_encode($data);
}else{
$data = http_build_query($data);
}

//$data isn't received in either format mode

curl_setopt($ch, CURLOPT_HTTPHEADER, $ch_options);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

$feedback = curl_getinfo($ch);

curl_close($ch);

编辑:决定这一切的代码(在 app.post 之后调用,与 http 一起使用。仅使用 https,此功能 [app.post('/post'...] 失败 AFAIK)

if(protocol == "https"){
preparedApp = require(protocol).createServer(sslOptions,app);
}else if(protocol == "http")
preparedApp = require(protocol).Server(app);

preparedApp.listen(socket_port, function(){
//literally nothing here
});

$feedback转储:

print_r: 
Array
(
[url] => https://127.0.0.1:socket_port/posts
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 1
[redirect_count] => 0
[total_time] => 0.005724
[namelookup_time] => 1.1E-5
[connect_time] => 5.5E-5 //IT IS connecting / knows presence, but doens't route /posts...
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 127.0.0.1
[certinfo] => Array
(
)

[primary_port] => socket_port
[local_ip] => 127.0.0.1
[local_port] => 54576
)

最佳答案

经过一些研究,我注意到 curl_exec($ch) 返回 false。在编程抛出诸如

之后
try{ $test = curl_exec($ch)

if ($test)
throw new Exception(curl_error($ch), curl_errno($ch));

} catch(Exception $e) {

trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);

}

我收到错误 Curl 失败,错误 #51:SSL:证书使用者名称“mydomain.com”与目标主机名“127.0.0.1”不匹配

TL;DR:所以我刚刚添加

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

到 ch 选项,它现在正在工作

关于php - socket.io 中的 app.post ('/posts' 带有 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34339340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com