Home > php教程 > php手册 > php中运用http调用的GET和POST方法示例,getpost

php中运用http调用的GET和POST方法示例,getpost

WBOY
Release: 2016-06-13 09:24:38
Original
1120 people have browsed it

php中运用http调用的GET和POST方法示例,getpost

使用到的函数是curl_init, curl_setopt, curl_exec,curl_close。

默认是GET方法,可以选择是否使用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方法:

$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

PHP $_POST与$_GET以及$_REQUEST的不同与用法(网上的文章免了)

HTTP请求有POST和GET。在写表单form时可以指定action为post或get。数组$_POST中保存POST方法传递的变量, $_GET保存GET方法传递的变量。$_REQUEST中包含二者。
例如





在t.php中,可以使用$_GET['aaa']获得网页表单中填写的数据.

当form中的action为get时使用$_GET;action为post时用$_POST。二者都可用 $_REQUEST
 

[php]什时用接收值get与post

看你提交方式是GET还是POST,一般表单提交有method指定,地址栏传的均用$_GET去取,如:www.tbsoo.com/cases.htm?s=&page=4 里page就用GET去取,如果你的PAGE还有从表单里提交的,那就用$_REQUEST,或者写个判断,GET取不到用POST取,不过还是用REQUEST最方便
 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template