如何将POST转换为URL?

时间:2013-07-01 13:00:26

标签: php post input http-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

当我点击该按钮时,这是来自Live 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(直到此处是网站的链接,我想添加此内容)duree = 1&amp; travail = submit 没有工作http://www.kraljevine.com/Action.php?action=338&n=688&t=mine&duree=1&travail=submit因此我想知道是否可以这样做。

3 个答案:

答案 0 :(得分:3)

首先,您需要了解 POST GET 的用途。

  • 如果您想发送数据,请使用发布

  • 如果您想根据某些参数获取数据,请使用 GET

使用 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脚本传递变量没有区别。

明智地使用它。

答案 1 :(得分: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>

答案 2 :(得分:1)

简短的回答是否定的。

根据定义,GET变量在URL中发送, 和POST变量在请求的正文中发送。

因此,您无法按照要求使用URL轻松发送变量。

即使在POST请求中,您也可以通过参数实际捕获可能的URL,但我强烈建议您不要采用这种方法。

您可以在this帖子

中详细了解相关信息