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

WBOY
Release: 2016-07-13 10:17:52
Original
1036 people have browsed it

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);
Copy after login

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);
Copy after login

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





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:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!