首页 > 编程语言 >php post请求方法,不用curl方法的解决办法

php post请求方法,不用curl方法的解决办法

时间:2022-12-26 12:00:55浏览次数:38  
标签:url res send id post php data curl

/**
 * file_get_contents方法 请求
 * @param string $url 接口url
 * @param string $post_data 接口参数
 * @return   string
 */
if (!function_exists('send_post')) {
    function send_post($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间(单位:s)
            )
        );
        $context = stream_context_create($options);
        $result = @file_get_contents($url, false, $context);
        return $result;
    }
}

  调用实例

 

  $data = array(
            "mobile" => $orderData['phone'],
            'pay_price' => $orderData['orderAmount'],
            'send_price' => 0,
            'id' => 0,
            'mall_id' => $merchantInfo['xiaowei_id'],
        );
        $url = 'https://xiaowei23.shop.test/web/index.php?_mall_id='.$merchantInfo['xiaowei_id'].'&r=api/open/balance-recharge';
        $res = send_post($url,$data);
        // dd($res);
        $res = json_decode($res,true);

  

标签:url,res,send,id,post,php,data,curl
From: https://www.cnblogs.com/kevin-yang123/p/17005441.html

相关文章

  • libcurl使用心得-包括下载文件不存在处理相关
    Libcurl为一个免费开源的,客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平台,支持Windows,Unix,Linux等,线程安全,支持Ipv6。并且易于使用。http://cur......
  • curl常用设置-涉及超时相关
    curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);//在屏幕打印请求连接过程和返回http数据curl_easy_setopt(curl,CURLOPT_TIMEOUT,10);//接收数据时超时设置,如果10......
  • postman 如何参数中传json数据
    最近弄前端,测试须自己测试接口,参数中有个data里面是json对象格式的。弄好一会传不上去。tips:1.选中了raw,才会选取raw所写的参数;如果选中x-www-form-urlencoded会传x-ww......
  • 为什么“去O”唯有PostgreSQL?
     本文根据digoal(德哥)在〖2019DAMS中国数据智能管理峰会〗现场演讲内容整理而成。讲师介绍digoal(德哥),PostgreSQL中国社区发起人之一、常委、兼任社区大学校长。阿里云......
  • PHP Composer 虚拟依赖包 - 实现按需载入钉钉对应功能模块的 php sdk
    难得钉钉官方提供了完整的apisdk,各种语言的版本的都有,而且api覆盖面非常完整。但是,composer安装下来有大几十兆,这个不符合个人的品味,我想要按需加载。于是在构思了一......
  • postmarketOS 22.12发布
    postmarketOS是一个基于阿尔卑斯山的移动设备Linux发行版。该项目最新的版本是postmarketOS22.12,其中包括对移动操作系统的三个用户界面的升级。Sxmo、Phosh和Pla......
  • php魔术方法(1)
    PHP魔术方法目录PHP魔术方法概述:1、构造函数和析构函数。2、__sleep()3、__wakeup()概述:PHP魔术方法:一个预定义好的,在特定情况下自动触发的行为方法。魔术方法相关......
  • C#-Http协议通讯(五)-HttpClient_Get、Post、Put、Delete方法
    /***┌──────────────────────────────────────────────────────────────┐*│描述:C#-HttpClien......
  • [CTF] 攻防世界-simple_php
    题目<?phpshow_source(__FILE__);include("config.php");$a=@$_GET['a'];$b=@$_GET['b'];if($a==0 and $a){    echo $flag1;}if(is_numeric($b)){   ......
  • 基于thinkphp的服装女装男装衣服鞋子商城服装商城
    php开发的服装商城,主要有商品分类,详情,购物车,订单等功能。演示视频https://www.bilibili.com/video/BV1Li4y1P7P9/?share_source=copy_web&vd_source=ed0f04fbb713154db5c......