我正在尝试使用代理列表创建一个发布到 URL 的脚本。该脚本似乎可以在不设置代理的情况下正常工作(CURLOPT_PROXY 为 null),但如果设置了代理,它似乎无法正常工作。有人知道我在这里做错了什么吗?使用代理发布时遇到的错误是:
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.
我的代码是:
$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;