• PHP 构造 模拟 http 请求 https_request 支持GET和POST


     
    function https_request($url, $data = null)
    {
        $curl = curl_init();//初始化
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);//允许 cURL 函数执行的最长秒数。
        /*if (!empty($port)) {
            curl_setopt($curl, CURLOPT_PORT, $port);//可选的用来指定连接端口,默认80端口可不写
        }*/
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json;charset=UTF-8'));//设置请求目标url头部信息
        if (!empty($data)) {
            //$data不为空,发送post请求
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //$data:数组
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);//执行命令
        $error = curl_error($curl);//错误信息
        if ($error || $output == FALSE) {
            //报错信息
            return 'ERROR ' . curl_error($curl);
        }
        curl_close($curl);
        return $output;
    }

    下面是在php中输出html后用js提交表单

    echo "<html>";
    echo "<head>";
    echo "<title>Loading...</title>";
    echo "<meta http-equiv="content-Type" content="text/html; charset=UTF-8" />";
    echo "</head>";
    echo "<body>";
    echo "<form action="{$post_url}" method="post" id="frm3">";
    echo "<input type="hidden" name="pMerCode" value="{$pMerCode}">";
    echo "<input type="hidden" name="p3DesXmlPara" value="{$p3DesXmlPara}">";
    echo "<input type="hidden" name="pSign" value="{$pSign}">";
    echo "</form>";
    echo "<script language="javascript">";
    echo "document.getElementById("frm3").submit();";      
    echo "</script>";
    echo "</body>";
    echo "</html>";
  • 相关阅读:
    C语言学习笔记之 程序流程结构
    C语言学习笔记之 类型转换
    C语言学习笔记之 标准输入输出函数
    C语言学习笔记之 运算符
    bzoj 4322 东西分配问题
    bzoj 3240 矩阵乘法+十进制快速幂
    bzoj 4017 子序列和的异或以及异或的和
    bzoj 1934 最小割
    bzoj 3275 最小割
    bzoj 3931 最短路+最大流
  • 原文地址:https://www.cnblogs.com/shaoing/p/5620105.html
Copyright © 2020-2023  润新知