2015-01-05 232 views
0

我想使用curl發送POST請求,但不知道它爲什麼不起作用。 HTTP請求是:php-curl不適用於POST請求

類型:POST URLhttps://abc.com/server/386594/actions/?do=open HEADERS:授權:基本1234abc

當我做出要求使用curl(CLI),那麼它工作正常,但在PHP我沒有得到任何迴應。我的代碼是:

$headers = array("Authorization: Basic 1234abc"); 
$ch1 = curl_init(); 
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch1, CURLOPT_URL, "https://abc.com/server/386594/actions/"); 
curl_setopt($ch1, CURLOPT_POST, 1); 
curl_setopt($ch1, CUTLOPT_POSTFIELDS, "do=open"); 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
$vnc = curl_exec($ch1); 
echo $vnc; 
echo curl_error($ch1); 

我在哪裏錯了? :)

+0

沒有反應?甚至沒有錯誤? Curp在Php中啓用? –

+0

可能重複的[php curl不能在代理服務器上運行](http://stackoverflow.com/questions/20239364/php-curl-not-working-with-proxy-on-live-server) –

+0

@Abhinav no響應。沒有錯誤。是的捲曲適用於其他帖子並獲得rrquests以便其啓用。 – ashish

回答

0

請把代碼如下....

網址是不安全的網址,以便取消HTTPS,寫簡單的HTTP。

$headers = array("Authorization:Basic 1234abc"); 
          //remove the space 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$host_url); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST,true); 
            //remove 1 and put 'true' keyword 
    curl_setopt($ch, CURLOPT_POSTFIELDS,"do=open"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
    $curl_response = curl_exec($ch); 
相關問題