我尝试设置以下代码,通过https协议接受来自php和nodejs的curl请求。 我知道代码在nodejs端使用http ,但只要我将协议切换为https ,"RECEIVED"
就不会记录在nodejs中。这是:
app.post('/posts', function(req, res){
console.log("RECEIVED");
});
总结:
有人对此有任何想法吗?这是我的卷曲功能:
$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
)
答案 0 :(得分:0)
在做了一些研究后,我注意到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 failed with error #51: SSL: certificate subject name 'mydomain.com' does not match target host name '127.0.0.1'
TL; DR:所以我刚刚添加了
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
到ch选项,它现在正在工作