简体   繁体   English

来自服务器的PHP / CURL空回复

[英]PHP/CURL Empty Reply from Server

I have a NodeJS App running on my server and i have a CURL that submits a post request to where the app's port on my server. 我的服务器上运行有NodeJS应用程序,我的CURL可以向服务器上应用程序的端口提交发布请求。 I am able to normally do it if i visit the PHP page, but trying to execute it as a command line is a different story. 如果我访问PHP页面,我通常可以做到这一点,但是尝试以命令行方式执行则是另一回事了。 It keeps returning with the HTTP response code 0 and the error being "Empty Reply from Server" 它不断返回HTTP响应代码0,错误为“来自服务器的空回复”

PHP Curl (OOP) [$this->domain = http://domain:port , $url = /path/to/something]: PHP Curl(OOP)[$ this-> domain = http:// domain:port ,$ url = / path / to / something]:

protected function post($url, $data)
{   
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0'
    ));
    curl_setopt($ch,CURLOPT_URL,$this->domain.$url);
    curl_setopt($ch,CURLOPT_POST,count($data));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    //error_log(curl_error($ch));
    return $result;
}


Command Line Execution: 命令行执行:

curl https://rbx.shopping/Secure/IPNCron.php


Default page when visiting domain:port 访问domain:port时的默认页面

访问domain:port时的默认页面


Example on what should be returning: https://rbx.shopping/Bot 有关应返回什么的示例: https : //rbx.shopping/Bot

try to add cookie jar: 尝试添加饼干罐:

$ckfile = tempnam (sys_get_temp_dir(), rand().'cookiename');
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);

Also add this: 还要添加以下内容:

curl_setopt($handle, CURLOPT_ENCODING, 'identity');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM