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

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

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

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最方便
 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools