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. 全国IP段列表

    http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest Linux下执行如下命令可将中国大陆ip格式化并导出 wget -c htt ...

  2. django日志集成输出器

    在配置文件中 import os # ⽇志 LOGGING = { 'version': 1, # 自定义一个简单版本 'disable_existing_loggers': False, # 是否禁 ...

  3. NetBeans的一些快捷键

    Alt + Insert getter 覆盖toString方法 Shift+ F6 运行当前文件 F6 运行当前项目 Tab 完成代码片段 ctrl+\ 代码补全 Alt + Shift + F格式 ...

  4. springboot集成Thumbnailator压缩图片

    一.参考大神博客 1.https://blog.51cto.com/u_11269274/5118649 2.https://blog.csdn.net/weixin_44722978/article ...

  5. 生产环境自动备份win服务器所有web项目(IIS+项目代码)

    @echo offrem 功能:每月自动备份本服务器所有web项目rem 日期:2022.3.10rem 制作人:zl rem 定义变量Y为备份时间:YYYYMMset y=%date:~0,4%%d ...

  6. Npoi.Mapper 日期转换

    问题:Excel文档里有一些列是日期类型的数据,使用Mapper默认的转换,发现生成的实体,在有的系统环境下能正常转换,但是在有的系统环境下,转换的日期出现中文. 猜想是Excel文档里,日期列的单元 ...

  7. vue 使用 swiper vue-awesome-swiper

    文档地址 https://github.com/surmon-china/vue-awesome-swiper 演示地址 https://v1.github.surmon.me/vue-awesome ...

  8. linux 下用其他用户来执行命令

    sudo su - username -l -c "supervisorctl restart apps" -l , –login:加了这个参数之后,就好像是重新登陆一样,大部分环 ...

  9. 如何设置 iOS 开发环境

    原文:https://lwebapp.com/zh/post/how-to-set-up-the-ios-development-environment 介绍 移动互联网时代,掌握 iOS 开发和安卓 ...

  10. 高精度计算_vector

    #include<bits/stdc++.h> using namespace std; // return a+b; vector<int> add(vector<in ...