GET传值
$html = file_get_contents("URL?a=xxx&b=xxx");
dump($html);
函数file_get_contents():
file_get_contents
Reads entire file into a string
<?php
function file_get_contents(
string $filename,
bool $use_include_path = false,
$context,
int $offset = 0,
?int $length
): string|false { }
@param string $filename — Name of the file to read.
@param bool $use_include_path
[optional]
Note: As of PHP 5 the FILE_USE_INCLUDE_PATH constant can be used to trigger include path search.
@param resource $context
[optional]
A valid context resource created with stream_context_create. If you don't need to use a custom context, you can skip this parameter by null.
@param int $offset — [optional]
The offset where the reading starts.
@param int|null $length
[optional]
Maximum length of data read. The default is to read un
POST传值
$arr = ['key1' => value1,
'key2' => value2,
...
];
$html = send_post('URL',$arr);
dump($html);
函数send_post():
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function send_post($url, $post_data) {
$postData = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postData,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}