【问题标题】:laravel , How to return view html page from curl POST methodlaravel,如何从 curl POST 方法返回视图 html 页面
【发布时间】:2020-11-05 05:55:24
【问题描述】:

我正在使用 curl 从控制器发布一些变量,结果是一个带有 HTML 数据的页面,这正是我想要的,问题是如何在运行 curl 函数后显示这个 html 页面

这样的结果

   public function OnlineBanking($amount,$response_url)
    {
  
  $prm_date         =  gmdate("Y-m-d H:i:s",time()+(8*60*60));
  $prm_amount       =  $amount;
  $prm_mrhref       =  "R".time(); //"Order-KAS-".time();
  $prm_mrhid        =  *****; // test MID
  $prm_mrhsKey      =  "*****;";// test secret key
  $prm_payment_mrh_hash = sha1($prm_mrhsKey . $prm_mrhid . $prm_mrhref . str_replace('.', '', $prm_amount));
  $prm_returnURL      = $response_url; // return URL once tranx process completes.
  $prm_POSTURL      = "https://www.example.com/gateway.php"; //Payment gateway connecting page
  
        $postData['ord_date'] = $prm_date;     
        $postData['ord_returnURL'] = $prm_returnURL;      
        $postData['ord_totalamt'] = $prm_amount;
        $postData['ord_mercref'] = $prm_mrhref;
        $postData['ord_mercID'] = $prm_mrhid;
        $postData['merchant_hashvalue'] = $prm_payment_mrh_hash;
        $res = self::curlRequest($prm_POSTURL,$postData);
        return $res;
   
    }


    public static function curlRequest($url, $data = null)
    {

        $curl = curl_init();
        curl_setopt_array($curl, [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_POSTFIELDS =>  http_build_query($data),
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST"
        ]);

        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        return $response;
    }

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    你需要设置CURLOPT_RETURNTRANSFER => true 你可以阅读它here

    然后你只需要echo你的输出

    类似的问题 managing curl output in php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-22
      • 2020-08-16
      • 1970-01-01
      • 2016-03-02
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多