带有标头的PHP cURL无效

时间:2013-06-01 17:25:22

标签: php curl

我正在尝试使用curl

将数据发送到远程页面

以下是表格部分的内容:

<form action="" method="POST" enctype="multipart/form-data">
    <table align="center" cellspacing="0" cellpadding="5">
    <tr><td>Type: </td><td width=100%><select name="service">

    <option value="3">blah blah</option>
    <option value="4">blah blah </option>

              <option value="10"blll</option>
              <option value="11">bbbb</option>

    </select></td>
    <tr><td>Link: </td><td><textarea name="url" cols="120" rows="10"></textarea></td>
    <tr><td>Quantity: </td><td><input type="text" name="count" placeholder=""></td>
    <tr><td>Initial Count (not required): </td><td><input type="text" name="incount" placeholder="" value="-1"></td>
    <tr><td colspan=2><input type="submit" name="submit" value="Submit"></td>
    </table>
    </form>

我正在使用这个curL CODE:

$header = array("Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryg5cfCMAC4o4JEbaz");
$postfields = array(); 
$postfields[] = array("service", "10"); 
$postfields[] = array("url", "something"); 
$postfields[] = array("count", "1000"); 
$postfields[] = array("incount", "-1"); 
$postfields[] = array("submit", "Submit");  

$proxy = '155.241.126.244:60099';
$proxyauth = '123:123';

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, "http://xxxx/xx/news.php");

curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, "http://xxxx/xx/news.php"); 
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_exec ($ch);
curl_close($ch);

这似乎不起作用(这边没有错误,数据没有收到另一端),我在这里做错了什么?是标题吗?我认为enctype =“multipart / form-data”是我的敌人..

1 个答案:

答案 0 :(得分:0)

添加以下选项:

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 

如果您不关心证书检查并想要禁用is。

请注意,必须同时使用以下选项:

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);