1. 传参格式 json

function post_http($array='',$url)
{
$ch = curl_init();
$header = array('Content-Type: application/json; charset=utf-8','Accept: application/json','secretKey:xxxxxxxx','signKey:xxxxxxxxxxx12');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//https
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 2);
//curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
 
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post设置头
// curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8080');//设置代理服务器 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
// post的变量
$arr = json_encode($array,);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
//打印获得的数据
return json_decode($result,true);
 
}
 
 
2. body体字符串式 表单传参 数组
 
function post_http($url)
{
 
//方法1 自己拼接
$body = "key=val&key1=val2"; 
 
//方法 2
//或用  $data = ['key' => 'val', 'key1' => 'val1'] ;$body = http_build_query($data) ;构建返回一个 URL 编码后的字符串
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
//打印获得的数据
return json_decode($result,true);
 
}
 
 
 
 
 
 

curl post请求body体内传参数的更多相关文章

  1. angularjs发送delete请求传参数的方法

    angularjs使用$http.delete()发送请求,默认是没法通过变量来传参数

  2. 用jQuery.ajaxWebService请求WebMethod,Ajax处理实现局部刷新;及Jquery传参数,并跳转页面 用post传过长参数

    首先在aspx.cs文件里建一个公开的静态方法,然后加上WebMethod属性. 如: [WebMethod]  public static string GetUserName()   {  //. ...

  3. PHP中CURL方法curl_setopt()函数的一些参数

    bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置,v ...

  4. PHP中CURL方法curl_setopt()函数的一些参数 (转)

    bool curl_setopt (int ch, string option, mixed value) curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置, ...

  5. 转:PHP中的使用curl发送请求(GET请求和POST请求)

    原文地址:http://www.jb51.net/article/104974.htm 使用CURL发送请求的基本流程 使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤: 1.初始 ...

  6. 使用PHP中的curl发送请求

    使用CURL发送请求的基本流程 使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤: 初始化连接句柄: 设置CURL选项: 执行并获取结果: 释放VURL连接句柄. 下面的程序片段是 ...

  7. HTTP入门(一):在Bash中curl查看请求与响应

    HTTP入门(一):在Bash中curl查看请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MDN). 本文版权 ...

  8. web service上传参数代码实例

    web service上传参数代码实例 这次做的项目用到webservice比较多,最开始在网上看的参考dome,发现都不行,后来发现安卓4.0以后有很大的不同,在做传参时,有些东西需要注意: 第一, ...

  9. spring mvc 传参数

    1.页面:(1)js传参数:location.href="${ctx }/forum/changeCtm.html?ctmId="+id; (2)将内容写在form表单里面,然后用 ...

  10. curl post请求

    libcurl发送post请求,包括httpheader参数 static size_t getCharCode(void *ptr, size_t size, size_t nmemb, void ...

随机推荐

  1. Jenkins拉取GitHub上代码

    1.github 生成 Personal Access Token 2.github 设置 GitHub webhooks (具体需要持续集成的项目),新建或者设置现有项目的 webhooks 选项, ...

  2. linux重置密码和单用户模式

    CentOS7.9 CentOS7系统root密码丢失找回方法(史上最好) 1. 重新启动或开启CentOS7系统,在选择进入系统Grub菜单界面如下图1-1,根据提示按"e"小写 ...

  3. android studio 导出 release aar

  4. Vulnhub 靶场 DOUBLETROUBLE: 1

    Vulnhub 靶场 DOUBLETROUBLE: 1 前期准备 靶机地址:https://www.vulnhub.com/entry/doubletrouble-1,743/ kali攻击机: 靶机 ...

  5. pdf2docx:可将 PDF 转换成 docx 文件的 Python 库

    pdf2docx:https://github.com/dothinking/pdf2docx 可将 PDF 转换成 docx 文件的 Python 库. from pdf2docx import p ...

  6. 10 个常用的 JS 工具库,80% 的项目都在用!

    Day.js 一个极简的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持一样, 但体积仅有2KB. npm install dayjs 基本用法 import ...

  7. CSS3选择器nth-child(n)

    CSS3选择器nth-child(n)实现隔几行选择元素 nth-child(n),n 可以是数字.关键词或公式.选择器匹配属于其父元素的第N个子元素,不论元素的类型. 序号写法:li:nth-chi ...

  8. geoserver官网

    https://www.osgeo.cn/geoserver-user-manual/index.html

  9. mariadb数据库查询(select)

    查询基本使用(条件,排序,聚合函数,分组,分页) 示例:--创建学生表 create table students ( id int unsigned not null auto_increment ...

  10. GIT 上传文件出错:fatal: Could not read from remote repository. 解决方案

    问题 git push -u origin master 执行后报错 fatal: Could not read from remote repository.  解决方案 1. git执行 git ...