2012-09-13 57 views
0

我試圖使用curl將圖像和更多選項發送到服務器,但我不知道爲什麼它不起作用。這裏是代碼:發送表單到https

<?php 

header('Location: https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxx&campaignid=xxxx&type=smrc'); 

$uploadUrl = "C:\wamp\www\autofill\demo_300x250.png"; 
$uploadUrl = "@$uploadUrl"; 


$post_data['description'] = 'Name'; 
$post_data['url'] = 'http://www.url.pl'; 
$post_data['campaignid'] = xxxxx; 
$post_data['clientid'] = xxxxx; 
$post_data['bannertext'] = 'some text'; 
$post_data['upload_smrc'] = $uploadUrl; 

    foreach ($post_data as $key => $value) 
{ 
    $post_items[] = urlencode($key) . '=' . urlencode($value); 
} 
$post_string = implode ('&', $post_items); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_VERBOSE, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_string); 
curl_setopt ($ch, CURLOPT_REFERER, "https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxxx&campaignid=xxxxx&type=smrc"); 
curl_setopt ($ch, CURLOPT_URL, 'https://www.reporo.com/analytics/inventory-advertiser-banner-update.php'); 
$upload_result = curl_exec ($ch); 

curl_close ($ch); 

?> 

$ post_data中的索引是正確的。該表單與CURLOPT_REFERER處於同一鏈接。現場行動我形式包含:inventory-advertiser-banner-update.php。

此外,我無法使用curl登錄到此網站,但是當我之前登錄時,重定向工作,因此它應該工作。

這個網站的網站可能無法使用捲曲嗎?我問,因爲之前我有問題登錄,我沒有解決,現在這個。

也許有辦法解決?

問候。

+0

你得到的捲曲錯誤是什麼。可能是由於安全證書問題。見http://stackoverflow.com/questions/521418/reading-ssl-page-with-curl-php和http://unitstep.net/blog/2009/05/05/using-curl-in-php-to -access-https-ssltls-protected-sites/ –

+0

沒有捲曲錯誤;/ –

回答

-1

你很可能有問題,CURLOPT_SSL_VERIFYHOST

嘗試

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
+0

我在問題文章中編輯了代碼,但它仍然不起作用;/ –

+0

請注意[禁用VERIFYPEER或VERIFYHOST會使連接易受MITM攻擊(http://stackoverflow.com/a/13742121/372643)。 – Bruno

0

這可能不是原因,但你需要urlencode POST關鍵字和值,如果你手動構建POST字符串。

foreach ($post_data as $key => $value) { 
    $post_items[] = urlencode($key) . '=' . urlencode($value); 
} 
$post_string = implode ('&', $post_items); 

否則,你會得到各種意想不到的結果,如果你的任何鍵或值包含&=

話雖這麼說,你可以使用數組直接與CURLOPT_POSTFIELDS代替:

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);

+0

我編輯並仍然無法正常工作。 –

1

關閉SSL對等驗證不是個好主意。 如果你想使用SSL等認證你可以使用在Windows下一個解決方案在全球範圍的所有應用程序:

  1. 下載文件,根證書從這裏: http://curl.haxx.se/docs/caextract.html
  2. 添加爲php.ini:

curl.cainfo=C:/path/to/ca-bundle.crt

這就是所有的魔術,CURL現在可以驗證證書。