2009-07-17 86 views
0

我會保持這個很好和短。CURL發佈數據的問題

我試圖將值發佈到遠程窗體。

此代碼是可以正常使用:

$url = "http://eirestudio.net/blog/"; // URL to POST FORM. 

$post_fields = "s=test"; 

$ch = curl_init(); // Initialize a CURL session. 
curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter. 
curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); // Pass form Fields. 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return Page contents. 
$result = curl_exec($ch); // grab URL and pass it to the variable. 
curl_close($ch); // close curl resource, and free up system resources. 
echo $result; // Print page contents. 

但是當我測試它在另一領域失敗:

$url = "http://jobbank.fas.ie/servlet/Watis?SESS=50306_1&TEMPLATE=WWW_JS_VAC_TEXTSEARCH.HTM&BACK=TEMPLATE%3DWWW_JS_VAC.HTM"; // URL to POST FORM. 

$post_fields = "TEXTSEARCH.JOBNAME=$search"; // 

$ch = curl_init(); // Initialize a CURL session. 
curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter. 
curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); // Pass form Fields. 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return Page contents. 
$result = curl_exec($ch); // grab URL and pass it to the variable. 
curl_close($ch); // close curl resource, and free up system resources. 
echo $result; // Print page contents. 

你能找出什麼毛病第二條碼?

更新:下面是一個例子:http://www.keithdonegan.com/labs/

更新2:現場HTTP頭

http://www.keithdonegan.com/labs/process.php

POST /labs/process.php HTTP/1.1 
Host: www.keithdonegan.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-gb,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://www.keithdonegan.com/labs/ 
Cookie: __utma=168444603.2571244565690463700.1247813169.1247813169.1247813169.1; __utmb=168444603.1.10.1247813169; __utmc=168444603; __utmz=168444603.1247813169.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 24 
search=web&submit=Search 
HTTP/1.x 200 OK 
Date: Fri, 17 Jul 2009 07:02:17 GMT 
Server: Apache/2.0.52 (Red Hat) PHP/4.4.7 FrontPage/5.0.2.2635 
X-Powered-By: PHP/5.2.5 
Keep-Alive: timeout=15, max=100 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: text/html 
---------------------------------------------------------- 
http://www.keithdonegan.com/watis1.css 

GET /watis1.css HTTP/1.1 
Host: www.keithdonegan.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729) 
Accept: text/css,*/*;q=0.1 
Accept-Language: en-gb,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://www.keithdonegan.com/labs/process.php 
Cookie: __utma=168444603.2571244565690463700.1247813169.1247813169.1247813169.1; __utmb=168444603.1.10.1247813169; __utmc=168444603; __utmz=168444603.1247813169.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) 
If-Modified-Since: Fri, 17 Jul 2009 06:46:20 GMT 

HTTP/1.x 404 Not Found 
Date: Fri, 17 Jul 2009 07:02:17 GMT 
Server: Apache/2.0.52 (Red Hat) PHP/4.4.7 FrontPage/5.0.2.2635 
X-Powered-By: PHP/5.2.5 
X-Pingback: http://www.keithdonegan.com/xmlrpc.php 
Expires: Wed, 11 Jan 1984 05:00:00 GMT 
Cache-Control: no-cache, must-revalidate, max-age=0 
Pragma: no-cache 
Last-Modified: Fri, 17 Jul 2009 07:02:17 GMT 
Keep-Alive: timeout=15, max=100 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: text/html; charset=UTF-8 
---------------------------------------------------------- 
http://www.keithdonegan.com/pictures1/ndplogo.gif 

GET /pictures1/ndplogo.gif HTTP/1.1 
Host: www.keithdonegan.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729) 
Accept: image/png,image/*;q=0.8,*/*;q=0.5 
Accept-Language: en-gb,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://www.keithdonegan.com/labs/process.php 
Cookie: __utma=168444603.2571244565690463700.1247813169.1247813169.1247813169.1; __utmb=168444603.1.10.1247813169; __utmc=168444603; __utmz=168444603.1247813169.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) 

HTTP/1.x 404 Not Found 
Date: Fri, 17 Jul 2009 07:02:17 GMT 
Server: Apache/2.0.52 (Red Hat) PHP/4.4.7 FrontPage/5.0.2.2635 
X-Powered-By: PHP/5.2.5 
X-Pingback: http://www.keithdonegan.com/xmlrpc.php 
Expires: Wed, 11 Jan 1984 05:00:00 GMT 
Cache-Control: no-cache, must-revalidate, max-age=0 
Pragma: no-cache 
Last-Modified: Fri, 17 Jul 2009 07:02:17 GMT 
Keep-Alive: timeout=15, max=100 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: text/html; charset=UTF-8 
---------------------------------------------------------- 
http://www.keithdonegan.com/pictures1/eurologo.gif 

GET /pictures1/eurologo.gif HTTP/1.1 
Host: www.keithdonegan.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729) 
Accept: image/png,image/*;q=0.8,*/*;q=0.5 
Accept-Language: en-gb,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://www.keithdonegan.com/labs/process.php 
Cookie: __utma=168444603.2571244565690463700.1247813169.1247813169.1247813169.1; __utmb=168444603.1.10.1247813169; __utmc=168444603; __utmz=168444603.1247813169.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) 

HTTP/1.x 404 Not Found 
Date: Fri, 17 Jul 2009 07:02:17 GMT 
Server: Apache/2.0.52 (Red Hat) PHP/4.4.7 FrontPage/5.0.2.2635 
X-Powered-By: PHP/5.2.5 
X-Pingback: http://www.keithdonegan.com/xmlrpc.php 
Expires: Wed, 11 Jan 1984 05:00:00 GMT 
Cache-Control: no-cache, must-revalidate, max-age=0 
Pragma: no-cache 
Last-Modified: Fri, 17 Jul 2009 07:02:18 GMT 
Keep-Alive: timeout=15, max=100 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: text/html; charset=UTF-8 
---------------------------------------------------------- 
+0

是否有回來的響應具體的錯誤?你確定服務器啓動了嗎?我只是嘗試了一些命令行curl請求,其中一些超時。 – seth 2009-07-17 06:27:58

+1

你叫什麼「失敗」? 你得到一個錯誤或任何東西? 在第二種情況下,$ search包含什麼? (也許urlencoding它可以幫助嗎?) – 2009-07-17 06:28:30

回答

1

由於新的知識開始另一個答案。我很無聊,並決定進行調查。您的postvars必須包含所有輸入字段,您只有TEXTSEARCH.JOBNAME。該網站必須全部或默認回到模板頁面。

這樣:

$search = 'plumber'; 
$post_fields = "TEXTSEARCH.JOBNAME=$search"; 

$post_fields .="&REQUEST.WWW_JS_VAC_TEXTSEARCH=Search"; 
$post_fields .="&TEXTSEARCH.DESCRIPTION= &TEXTSEARCH.LOCATION="; 

,如果你填好這樣,那麼你會得到包括像「搜索得到X結果」或任何

0

嘗試通過內部curopt_postfields所有崗位ARGS。你正在通過一些URL

$url = "http://jobbank.fas.ie/servlet/Watis"; 
$post_fields = "TEXTSEARCH.JOBNAME=$search&SESS=50306_1&TEMPLATE=WWW_JS_VAC_TEXTSEARCH.HTM&BACK=TEMPLATE%3DWWW_JS_VAC.HTM";