最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP 使用 POST 方式向https发送数据请求
时间:2022-06-24 16:47:40 编辑:袖梨 来源:一聚教程网
例子
| 代码如下 | 复制代码 |
|
$data = '{"type":"news", "offset":50, "count":20 }'; // 发送数据 // 输出 ';'; |
|
例子
方法1感觉也很笨拙,似乎也很难满足我的需求,最后忘记在哪个英文网站上找到了下面这个方法:
| 代码如下 | 复制代码 |
| function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } |
|
试用了一下,感觉效果非常好,简洁,通用,而且返回的内容仅仅是Body中内容
相关文章
- 蓝色星原旅谣新芽山谷好玩吗 05-07
- 《和平精英》转盘160碎片价格解析-碎片价值与保底机制详解 05-07
- 《和平精英》国际服怎么注册-国际服的注册流程 05-07
- 微掌柜如何签约快递员 05-07
- 《和平精英》颜团子套装介绍-服装与配件全解析 05-07
- 《和平精英》车送重复怎么处理-车送重复的处理方法 05-07