$query_info = ['dir' => 'station', 'type'=>1];
$context = stream_context_create([
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => http_build_query($query_info),
'timeout' => 20
),
]);
file_get_contents('http://jiejiang.ytddcw.com/api/admin-api/get-images', false,
$context);
string file_get_contents ( string $filename [, bool $use_include_path [, resource $context [, int $offset [, int $maxlen ]]]] )
- $filename:URL字符串。
- $use_include_path:是否使用文件之前include_path()设置的路径,如果使用,在文件地址找不到时,会自动去include_path()设置的路径去寻找,网页地址中我们设置为false。
- $context:环境上下文,resource类型,由函数 stream_context_create() 返回的 context来设置,也是我们进行file_get_contents()函数扩展的重点,接下来再说。
- $offset:读取的内容相对文件开始内容的偏移字节,我们读取网页内容,要保证HTML文档的完整性,所以可以设置为0或者不设置,默认为0。
- $maxlen:顾名思义,是读取文件的最大字节数,同offset我们不设置,读取网页的全部内容。