php通过CURL模拟post提交请求
<?php
header("Content-type:text/html;charset=utf-8"); class Test{ public function request_post($url = '', $param = '',$headers = array()){
if (empty($url) || empty($param) || empty($headers)) {
return false;
} $postUrl = $url;
$curlPost = $param;
$curlHeader = $headers;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, );//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, );//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch); return $data;
} public function testAction(){
$url = 'http://web.zhimabot.com:8080/parsor9/robot';
$post_data['app_id'] = '';
$post_data['client_id'] = '';
$post_data['session_id'] = '';
$post_data['intent_update'] = '';
$post_data['query'] = '播放刘德华的忘情水'; $headers = array();
array_push($headers, "Content-Type: application/json; charset=utf-8","Accept: application/json");
$post_data = json_encode($post_data,JSON_UNESCAPED_UNICODE); $res = $this->request_post($url, $post_data,$headers);
return $res;
} } function fn(){
$action = new Test();
$result = $action->testAction();
var_dump($result);
} fn(); ?>
php通过CURL模拟post提交请求的更多相关文章
- php通过CURL模拟get提交请求
方式一: $host = "http://jisunews.market.alicloudapi.com"; $path = "/news/get"; $met ...
- CURL 模拟http提交
1:CURL模拟get提交 private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETUR ...
- php中curl模拟post提交多维数组(转载)
原文地址:http://www.cnblogs.com/mingaixin/archive/2012/11/09/2763265.html 今天需要用curl模拟post提交参数,请求同事提供的一个接 ...
- 【转载】curl 模拟 GET\POST 请求,curl查看响应头 以及 curl post 上传文件
补充说明:curl查看响应头 curl -I "http://www.baidu.com"HTTP/1.1 200 OK #HTTP协议 HTTP 返回码Server: Tengi ...
- cURL模拟POST提交数据
首先,是这个代码: <?php //curl模拟post提交数据$url = "http://127.0.0.1/immoc/output.php";$post_data = ...
- php使用curl模拟多线程发送请求
每个PHP文件的执行是单线程的,但是php本身也可以用一些别的技术实现多线程并发比如用php-fpm进程,这里用curl模拟多线程发送请求.php的curl多线程是通过不断调用curl_multi_e ...
- [转]php模拟post提交请求,调用接口
本文转自:https://www.cnblogs.com/jiqing9006/p/3949190.html /** * 模拟post进行url请求 * @param string $url * @p ...
- php模拟post提交请求,调用接口
/** * 模拟post进行url请求 * @param string $url * @param string $param */ function request_post($url = '', ...
- php模拟post提交请求与调用接口
/** * 模拟post进行url请求 * @param string $url * @param string $param */ function request_post($url = '', ...
随机推荐
- python学习第40天
# 多表查询 # 索引的基础理论 + 数据准备
- mysql设计表时注意事项
说明:本文是对项目过程中的一些要求的简单汇总整理,主要是供个人本身参考... 一.表设计 1. 在创建表结构时,表名.字段需要见名知意,不采用拼音 create table `tb_abc` ( ...
- 【原创】大数据基础之Kerberos(1)简介、安装、使用
kerberos5-1.17 官方:https://kerberos.org/ 一 简介 The Kerberos protocol is designed to provide reliable a ...
- grep,find
grep是强大的文本搜索工具,他可以对文件逐行查看,如果找到匹配的模式,就可以打印出包含次模式的所有行,并且支持正则表达式 find查找文件的grep是来查找字符串的,文件的内容 grep 文件的内容 ...
- VUE 多页面配置(一)
1. 概述 1.1 说明 项目开发过程中会遇到需要多个主页展示情况,故在vue单页面的基础上进行配置多页面开发以满足此需求. 2. 实例 2.1 页面配置 2.1.1 默认首页 使用vue脚手架搭建后 ...
- Confluence 6 为登录失败编辑,禁用和配置验证码
在默认的情况下,验证码将会在失败登录次数达到的时候显示. 如果为登录失败编辑,禁用和配置验证码: 在屏幕的右上角单击 控制台按钮 ,然后选择 General Configuration 链接. 在左侧 ...
- Confluence 6 代理和 HTTPS 详细配置指南链接
详细配置指南 更多有关连接器示例,我们提供了一些按步骤配置的指南来帮助你启用 HTTPS 并正确配置你的代理. HTTPS: Running Confluence Over SSL or HTTPS ...
- nginx之请求限制与连接限制
模块limit_conn_module与limit_req_module limit_conn_module语法 limit_req_module语法 附: http长连接与短连接
- JMeter进行一次简单的压力测试
测试目的:10个用户并发打开百度首页(https://www.baidu.com/),百度能否正常响应. 操作步骤 一.打开JMeter 打开后的界面如下: 二.右击“测试计划”,添加线程组 三.设置 ...
- 【python】打印函数调用栈
traceback.print_stack()