douzui0143 2013-02-13 16:32
浏览 250
已采纳

PHP CURL使用代理进行POST

I'm trying to create a script that posts to an URL, using a list of proxies. The script seems to work fine without setting a proxy (CURLOPT_PROXY to null), but with a proxy set it does not seem to work. Does anybody know what I'm doing wrong here? The error I'm getting when posting with a proxy is:

ERROR

The requested URL could not be retrieved

Invalid Request error was encountered while trying to process the request:

POST /###/ HTTP/1.1
Host: ###
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 368
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------9b24e849cac0
Some possible problems are:

Missing or unknown request method.

Missing URL.

Missing HTTP Identifier (HTTP/1.0).

Request is too large.

Content-Length missing for POST or PUT requests.

Illegal character in hostname; underscores are not allowed.

And my code is:

$url = 'urltopost';
$proxy = 'proxy:port';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'postname1' => 'value1',
    'postname2' => 'value2'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;
  • 写回答

1条回答 默认 最新

  • doude4201 2013-02-13 16:35
    关注

    You are missing the PROXYPORT option... You can't use the proxy:port notation

    curl_setopt($ch, CURLOPT_PROXY,             "YOUR PROXY HOST");         
    curl_setopt($ch, CURLOPT_PROXYPORT,         "YOUR PROXY PORT");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch