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 = '', ...
随机推荐
- WebApi中使用session
webapi默认是不支持session的,要通过一些手动配置来开启Session功能 在Global.asax里添加: 导入命名空间: using System.Web.SessionState; p ...
- Go Rand小结
对于Random的使用,在业务中使用频率是非常高的,本文就小结下常用的方法: 在Golang中,有两个包提供了rand,分别为 "math/rand" 和 "crypto ...
- Git如何克隆远程仓库
1.首先选择一个合适的地方创建一个空目录 mkdir learngit 2.通过git Init命令把这个目录变成git可以管理的仓库,瞬间git就把仓库建好了 3.将编写的文件放到 lear ...
- 【原创】Linux基础之命令行浏览器links
有时服务器环境受限,比如在内网环境不能暴露端口从外网访问,用curl看html代码比较累,这时可以使用命令行浏览器来查看相关页面 links 官方:http://links.twibright.com ...
- Appium新版本不再支持ByName定位了怎么办
appium版本在1.5以后就不再支持ByName的定位,本文章仅介绍在appium1.6.3/1.6.4/1.6.5版本下如何支持ByName定位,适用于安卓.在使用appium1.5之后的版本时, ...
- 彻底删除mysql服务(清理注册表)
前言 由于安装某个项目的执行文件,提示要卸载MySQL以便它自身MySQL安装,然后我禁用了MYSQL服务,再把这个文件夹删除后,发现还是提示请卸载MYSQL服务. ----------------- ...
- [PHP]命名空间的一些要点
1.命名空间前不能接"\": namespace MyProject\Sub\Level; // it's right; namespace \MyProject\Sub\Leve ...
- iOS10 远程通知需要有entitlements的支持
今天测试远程通知,发现ios9上可以收到,但是ios10上无法收到,原来是忘记开下面这个选项了: 这样看来iOS9 对这个entitlement没有什么依赖,但是10却是必须打开的!
- Python split()
split翻译为分裂. split()就是将一个字符串分裂成多个字符串组成的列表. split()当不带参数时以空格进行分割,当代参数时,以该参数进行分割. //---当不带参数时 example: ...
- css之relative
一.relative对absolute的限制作用 1.限制left/top/right/bottom定位.absolute默认是在也没的左上角,当父类设定为relative,absolute就被限制在 ...