0
我試圖創建一個腳本使用代理列表發佈到URL。該腳本似乎沒有設置代理(CURLOPT_PROXY爲空)正常工作,但與代理設置它似乎不工作。有人知道我在這裏做錯了嗎?與代理髮布時,我得到的錯誤是:PHP CURL使用代理到POST
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;
似乎現在工作。很奇怪,當我沒有添加任何POST變量時,代理:端口符號如何工作......但感謝您的快速回答! – user2069116 2013-02-13 16:53:29
嘿,雖然我並不反對這個解決方案,但是你能解釋一下爲什麼它不能以另一種方式工作嗎?我找不到任何地方......並且所有示例(以及curl_setopt()的PHP手冊)將端口和主機放在一起...謝謝! – Jull 2013-07-16 21:28:30
如果我沒有弄錯,全球環境變量也足夠了嗎? – 2017-04-17 17:52:09