2017-04-03 32 views
0

我有一個NodeJS應用程序在我的服務器上運行,我有一個CURL提交了一個post請求到我的服務器上的應用程序的端口。如果我訪問PHP頁面,通常可以做到這一點,但試圖將其作爲命令行執行則是另一回事。它一直與HTTP響應代碼0和誤差是PHP/CURL來自服務器的空回覆

PHP捲曲(OOP)[$這 - >域= http://domain:port,$ URL = /路徑/到/東西] 「從服務器空回覆」 返回:

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; 
} 


命令行執行:

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


默認頁面訪問時域:在什麼應該退還口

Default Page when visiting domain:port


例子: https://rbx.shopping/Bot

回答

0

嘗試添加餅乾罐:

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

還要加上這個:

curl_setopt($handle, CURLOPT_ENCODING, 'identity'); 
相關問題