Home >Backend Development >PHP Tutorial >Examples of GET and POST methods using http calls in php, getpost_PHP tutorial
The functions used are curl_init, curl_setopt, curl_exec, curl_close.
The default is GET method, you can choose whether to use Header:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "$url"); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_HEADER, 1); //如果设为0,则不使用header curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch);
POST method:
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'$url'); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); $vars =sprintf('from=%d&to=%d&subject=%s&body=%s',$from, $to, urlencode($subject), urlencode($body)); curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); $ret = curl_exec($ch); curl_close($ch);
HTTP requests include POST and GET. When writing a form, you can specify the action as post or get. The array $_POST stores the variables passed by the POST method, and $_GET stores the variables passed by the GET method. $_REQUEST contains both.
For example
4d353d6fe899c04db9988e14585aeea2
109ea16532c0afc8472249451c3d2b26
f5a47148e367a6035fd7a2faa965022e
In t.php, you can use $_GET['aaa'] to obtain the data filled in the web form.
Use $_GET when the action in the form is get; the action is post Use $_POST. Both are available $_REQUEST
It depends on whether your submission method is GET or POST. Generally, form submission has a method specified, and $_GET is used to retrieve the information passed in the address bar, such as: www.tbsoo.com/cases.htm?s=&page=4 where the page is Use GET to get it. If your PAGE is submitted from the form, then use $_REQUEST, or write a judgment. If you cannot get it with GET, use POST, but it is most convenient to use REQUEST