Home >Backend Development >PHP Tutorial >A small example of using php curl to simulate post requests. , curlpost_PHP tutorial

A small example of using php curl to simulate post requests. , curlpost_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 09:03:09931browse

A small example of using php curl to simulate post requests. , curlpost

1, local machine:

<?php

$uri = "http://www.jbxue.com/test.php";//这里换成自己的服务器的地址
// 参数数组
$data = array (
'name' => 'tanteng' 
// 'password' => 'password'
);

$ch = curl_init ();
// print_r($ch);
curl_setopt ( $ch, CURLOPT_URL, $uri );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$return = curl_exec ( $ch );
curl_close ( $ch );

print_r($return);

 

2, Remote server:

<?php

if(isset($_POST['name'])){
if(!empty($_POST['name'])){
echo '您好,',$_POST['name'].'!';
}
}

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1082308.htmlTechArticleA small example of using php curl to simulate a post request. , curlpost 1, local machine: ?php$uri = "http://www.jbxue.com/test.php";//Change here to the address of your own server//Parameter array $dat...
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