Home >Backend Development >PHP Tutorial >Examples of GET and POST methods using http calls in php, getpost_PHP tutorial

Examples of GET and POST methods using http calls in php, getpost_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:521078browse

Examples of GET and POST methods using http calls in php, getpost

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);

The difference and usage of PHP $_POST, $_GET and $_REQUEST (not included in online articles)

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

[php] When to use receive value get and post

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/887347.htmlTechArticleExamples of GET and POST methods using http calls in php. The functions used by getpost are curl_init, curl_setopt, curl_exec, curl_close. The default is GET method, you can choose whether to use Header:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn