2013-07-01 3 views
2

데이터를 전송하는 것이 가능합니다. 보통 URL을 사용하여 전송 버튼을 사용하여 전송해야합니다. 여기 POST를 URL로 변환하는 방법은 무엇입니까?

그런 버튼이 사이트에서 코드의 예입니다 :

<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 

내가 원하는 것은 URL로 게시물을 보내는 것입니다. 같은 뭔가 :

http://www.kraljevine.com/Action.php?action=338&n=688&t=mine (여기 전까지는 사이트에서 링크입니다, 나는이를 추가 할) = duree = 1 & 진통을 이 http://www.kraljevine.com/Action.php?action=338&n=688&t=mine&duree=1&travail=submit을 작동하지 않으며이 할 수있는 경우에는이 때문에 내가 궁금 제출합니다.

+0

cURL을 사용하여 post-paramters를 보낼 수 있습니다. – OptimusCrime

+0

사용 방법 GET man. 훨씬 더 간단합니다. 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

에 대한 자세한 내용을보실 수 있습니다 첫째는 POST이 사용된다 무엇을 얻을 알아야합니다. 당신이 SEND 데이터를 원하는 경우 데이터를 다음 를 GET 사용하는 일부 PARAMS에 따라 GET 하려면

  • 당신은 POST

  • 를 사용해야합니다. 로 데이터를 보내는 것은 의미가 없습니다

몇 가지 제한이에도 있습니다 GET. 한도에 대한 자세한 내용은 here을 참조하십시오.

CURL을 사용하면 POST 데이터를 다른 URL로 보낼 수 있습니다.

마지막 것은 연관 배열 입니다 $_REQUEST입니다
<?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); 
?> 

그 기본이 $ _GET의 내용을 포함하여 $ _POST과 : 여기

Here is good tutorial how to do it

이 튜토리얼에 따라 예를 간다 $ _COOKIE.
PHP 스크립트에서 사용할 수 있으며 변수가 PHP 스크립트에 전달되는 방법에는 차이가 없습니다.

현명하게 사용하십시오.

관련 문제