简体   繁体   English

带有标头的PHP cURL不起作用

[英]PHP cURL with header not working

I am trying to send data to a remote page using curl 我正在尝试使用curl将数据发送到远程页面

Here is the soruce of the form section : 这是表单部分的名称:

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

I am using this 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);

This doesn't seem to work ( NO ERROR ON THIS SIDE , DATA IS NOT RECEIVING ON THE OTHER END ) , What is it i am doing wrong here ? 这似乎不起作用(此端没有错误,另一端没有接收到数据),我在这里做什么错了? Is it the headers ? 是标题吗? I think the enctype="multipart/form-data" is my enemy .. 我认为enctype =“ multipart / form-data”是我的敌人。

Add the following option: 添加以下选项:

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 

if you don't care about certificate checking and want to disable is. 如果您不关心证书检查而想禁用它。

Note that the following options MUST being used together: 请注意,以下选项必须一起使用:

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

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

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