Home > Backend Development > PHP Tutorial > PHP curl simulates post submission data example_PHP tutorial

PHP curl simulates post submission data example_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:42:57
Original
910 people have browsed it

Copy code The code is as follows:

header("Content-type: text/html; charset =utf8");
/*
* Submit request
* @param $header array Domain name and other header settings that need to be configured array("Host: devzc.com");
* @param $ data string The data to be submitted 'user=xxx&qq=xxx&id=xxx&post=xxx'....
* @param $url string The url to be submitted 'http://192.168.1.12/xxx/xxx/api/' ;
*/
function curl_post($header,$data,$url)
{
$ch = curl_init();
$res= curl_setopt ($ch, CURLOPT_URL,$url ;
Curl_Setopt ($ ch, curlopt_post, 1);
CURL_SETOPT ($ ch, Curlopt_postfields, $ data); 1); CURL_SETOPT ($ ch, curlopt_httpheader, $header);
$result = curl_exec ($ch);
curl_close($ch);
if ($result == NULL) {
return 0;
}
return $result;
}

$url = 'http://127.0.0.1' ;

$header = array("Host:127.0.0.1",
"Content-Type:application/x-www-form-urlencoded",
'Referer:http://127.0.0.1/toolindex .xhtml',

'User-Agent: Mozilla/4.0 (compatible; MSIE .0; Windows NT 6.1; Trident/4.0; SLCC2;)');

$data = 'tools_id=1&env=gamma';
echo "argv:$data
";

$ret = curl_post($header, $data,$url);$utf8 = iconv('GB2312', 'UTF-8//IGNORE', $ret);

echo 'return:
'.nl2br($utf8 ).'
';
?>





http://www.bkjia.com/PHPjc/633584.html

www.bkjia.com

true

TechArticleCopy the code as follows: ? header("Content-type: text/html; charset=utf8"); / * * Submit request* @param $header array Domain name and other header settings that need to be configured array("Host: devzc.com")...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template