php - PHP stream_context_create
问题描述
我有这个测试代码:
//$url = 'https://www.random.org/integers/?num=1000&min=1&max=100&col=1&base=10&format=plain&rnd=new';
$url = 'https://www.random.org/integers/';
$data = array('num'=>1000, 'min'=>1, 'max'=>100, 'col'=>1, 'base'=>10, 'format'=>'plain', 'rnd'=>'new');
$options = array(
'http' => array(
'method' => 'GET',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'user_agent' => ini_get('user_agent'),
'content' => http_build_query($data),
'proxy' => null,
'request_fulluri' => true,
'follow_location' => 1,
'max_redirects' => 20,
'protocol_version' => 1.0,
'timeout' => ini_get('default_socket_timeout'),
'ignore_errors' => false
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo('<pre>');
echo($result);
echo('</pre>');
如果我使用第一个 url 页面可以正常工作,如果我尝试使用 stream_context_create 创建查询字符串,则响应不正确。
谁能帮我。Tks
解决方案
推荐阅读
- performance - 资产管理 - 基于资产(SPEED CAMERA POSITION API)
- python - openCV缺陷检测问题(如何让边框整齐?)
- asp.net-core - .Net 5.0 核心项目 - 向其中添加框架/元包?
- postgresql - 为什么我的 Pipelinewise ETL 没有将行插入雪花?
- android - 如何在 baseadapter 的 webview 上添加操作栏?
- mysql - Transaction + Select ... For Update... 跳过索引
- python - 使用 biopython 的 SeqIO 解析 genbank 文件格式
- c++ - condition_variable 用于信令和等待
- unit-testing - 如何访问视图并测试视图是否可见?
- vb.net - 如何遍历 XDocument