zoukankan      html  css  js  c++  java
  • 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>";
  • 相关阅读:
    Mac OS X下GnuPlot的安装
    为PHP编译imap扩展
    jQuery做个TextBox自动完成条
    sql 查询模块
    WinForm控件查找奇思
    支持拼音检索的TextBox扩展控件使用
    自定义控件重写Listbox实现item图标变换和item点击事件
    支持拼音检索的TextBox扩展控件
    (转)SendMessage API
    使用C#获取CPU及硬盘序列号的源代码
  • 原文地址:https://www.cnblogs.com/shaoing/p/5620105.html
Copyright © 2011-2022 走看看