2014-10-06 32 views
0

我認爲這很簡單,但我無法弄清楚。我有這種結構的表格:使用cURL POST到基本表格

<form name="input" action="DOTHINGS" method="POST"> 

<textarea rows="10" cols="30" name="rules"></textarea> 

<textarea rows="10" cols="30" name="facts"></textarea> 

<br><input type="submit" value="Submit"> 

所以我想發佈到規則和事實文本區域並提交。我曾嘗試以下:

curl -F "[email protected]/directory/file.txt" -F "[email protected]/directory/file.txt" http://localhost:1112/ 
curl -X POST -d "rules=junktext" http://localhost:1112/ 
curl --data "rules=junkdata&facts=junkdata" http://localhost:1112/ 

無論我怎麼努力,我得到The requested resource could not be found作爲響應。

我首先想到我的localhost:1112無法訪問,所以我嘗試了一些變體,並做了一個基本的curl localhost:1112,它返回了網站的內容,以便它能夠訪問該網址。然而,我只是無法獲得任何POST。我的語法或表單本身有問題嗎?

+0

也許您的服務器崩潰,如果你打它'POST' – 2014-10-06 18:02:27

+2

看起來你的URL應該是'http:// localhost:1112/DOTHINGS' – 2014-10-06 18:03:40

+0

@glennjackman就是這樣......我沒有想到表單動作是一個URL。所以curl正在尋找一個可操作的URL作爲參數? – AmericanKryptonite 2014-10-06 18:23:15

回答

-1

你可以用你的apache日誌來驗證發生了什麼。通常這會導致至少知道數據是否達到您的預期。

你可以在PHP中做到這一點,可能會得到更多的反饋。特別是因爲php CLI配置對通知和錯誤非常大聲。仍然從命令行執行,把它放在一個php文件中,並用php二進制文件執行php文件,而不是直接執行curl。如果你安裝了PHP,當然。如果你不知道它是什麼,請將代理的東西留空。

PHP例子:

<?PHP 
$data='x_response_code=1&x_response_reason_code=1&x_response_reason_text=This+transaction+has+been+approved.&x_ship_to_city=auburn&x_ship_to_state=New+York&x_ship_to_zip=13021&x_ship_to_country=United+States&x_amount=2.00&x_tax=0.00&x_duty=0.00&x_freight=0.00&x_tax_exempt=FALSE&x_po_num=&x_MD5_Hash=AF489908B0730A34FF3DF9&x_cvv2_resp_code=M&x_cavv_response=&x_test_request=false'; 

$response=curl_post_data_and_return('http://catalog.example.com/capture/CaptureAllFormData.php',$data,'','off'); 

echo "<pre>"; 
print_r($response); 

function curl_post_data_and_return($site,$data,$proxy,$proxystatus){ 
    $ch = curl_init(); 
    if ($proxystatus == 'on') { 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
     curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); 
     curl_setopt($ch, CURLOPT_PROXY, $proxy); 
    } 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_URL, $site); 
    curl_setopt($ch, CURLOPT_POST, TRUE); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
// curl_setopt($ch, CURLOPT_COOKIEFILE, "xxx.cookie.txt"); 
// curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
// curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com//search.asp'); 
    ob_start();  // prevent any output 
    return curl_exec ($ch); // execute the curl command 
    ob_end_clean(); // stop preventing output 
    curl_close ($ch); 
} 
0

我相信這樣的事情應該工作:

curl -X POST -d "rules=junktext" -H "Content-Type: application/x-www-form-urlencoded" http://localhost:1112/DOTHINGS