2013-07-01 78 views
2

是否可以發送數據,您只需使用url就可以正常使用提交按鈕發送數據?如何將POST轉換爲網址?

下面是代碼的例子從一個網站有這樣一個按鈕:

<form method="POST" action="Action.php?action=338&amp;n=688&amp;t=mine"><input type="hidden" id="Mine688" value="1" name="duree"><button value="submit" class="boutonsGeneral" type="submit" name="travail"><span title="" class="infoBoutonsGeneral"><span class="boutonsGeneral_separateur">&nbsp;</span><span class="boutonsGeneral_gain" id="gainMine688"><img width="48" height="24" src="images/items/itemArgent.png">+2,18</span></span>Munca <span class="boutonsGeneral_duree boutonsGeneral_dureeMoins" id="dureeMine688">1 hour</span></button></form> 

enter image description here

這是直播HTTP頭當我點擊該按鈕:

ww.kraljevine.com/Action.php?action=338&n=688&t=mine 

POST /Action.php?action=338&n=688&t=mine HTTP/1.1 
Host: ww.kraljevine.com/ 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2 
Accept-Encoding: gzip, deflate 
Referer: ww.kraljevine.com/EcranPrincipal.php?l=8 
Cookie: PHPSESSID=ec95ed7caf7c28f8a333; KC=account_name; KC2=1502cae30e04f5f55963e93; > > Glup=274; pageTamponVue=1 
Connection: keep-alive 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 22 
duree=1&travail=submit 

我想要做的是通過網址發送帖子。喜歡的東西:

http://www.kraljevine.com/Action.php?action=338&n=688&t=mine(直到這裏是從網站上的鏈接,我想補充這一點)綿延= 1個&勞苦=提交 不工作http://www.kraljevine.com/Action.php?action=338&n=688&t=mine&duree=1&travail=submit也正因爲如此,我想,如果能夠做到這一點。

+0

您可以使用cURL發送後置參數。 – OptimusCrime

+0

使用方法GET男人。它更簡單。使用get你有在url中顯示的變量。 – Gimmy

+0

無理由使事情變得複雜。如果參數在QUERYSTRING中使用GET,如果它們在表單上使用POST。就是這樣簡單,並且都在php代碼中以相同的方式訪問。 – CarlosB

回答

1

使窗體方法GET並將變量放在窗體的隱藏字段中。 例如:

<form method="GET" action="Action.php"> 
<input type="hidden" name="action" value="338" /> 
<input type="hidden" name="n" value="688" /> 
<input type="hidden" name="t" value="mime" /> 
...more html/php... 
</form> 
1

簡短的回答是否定的。

根據定義,GET變量在URL中發送, 和POST變量在請求的正文中發送。

所以,你不能通過使用URL發送你的變量,如你所請求的。

即使在POST請求中,您也許可以在物理上捕獲一個可能的URL參數,但我強烈建議您不要採用這種方法。

可以在this

3

閱讀更多關於它首先,你需要知道什麼POSTGET用於。

  • 如果你想SEND數據如果您想GET根據一些PARAMS數據,然後使用GET你應該使用POST

有與發送數據沒有意義GET也有一定的侷限性了這一點。你可以閱讀更多關於限制here

您可以隨時使用CURL發送POST數據到其他網址。

Here is good tutorial how to do it和這裏有雲基於本教程中的例子:

<?php 
$url = 'http://www.kraljevine.com/Action.php?action=338&n=688&t=mine'; 
$fields = array(
        'duree' => urlencode('1'), 
        'travail' => urlencode('submit') 
      ); 
//$fields can be extended with more params for POST submit always encode them with urlencode for these 2 examples of 1 submit it is not necessary but sometimes is really imporant to do it 

//url-ify the data for the POST 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
rtrim($fields_string, '&'); 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL, $url); 
curl_setopt($ch,CURLOPT_POST, count($fields)); 
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 

//execute post 
$result = curl_exec($ch); 

//close connection 
curl_close($ch); 
?> 

的最後一件事是$_REQUEST這是的關聯數組默認包含$ _GET內容,$ _ POST$ _COOKIE你可以在php腳本中使用它,並且這個變量是如何傳遞給php腳本的。

明智地使用它。