简体   繁体   English

如何通过HTTP Post将请求发送到php中的URL

[英]How can I send requests via HTTP Post to URL in php

I have website that has page for donation. 我的网站上有捐赠页面。 Merchants registered on the Gateway are to send transaction requests to GTPay via HTTP Post to URL https://ibank.gtbank.com/GTPay/Tranx.aspx 在网关上注册的商户将通过HTTP Post发送到GTPay的交易请求到URL https://ibank.gtbank.com/GTPay/Tranx.aspx

When I submit my request I see this page of the above URL displayed inside my donation page instead of taking me to the URL Below is my code: 当我提交请求时,我看到上述URL的页面显示在捐赠页面中,而不是带我到URL。以下是我的代码:

$url = 'https://ibank.gtbank.com/GTPay/Tranx.aspx';
$fields = array(
        'gtpay_mert_id' => urlencode($gtpay_mert_id),
        'gtpay_tranx_id' => urlencode($gtpay_tranx_id),
        'gtpay_tranx_amt' => urlencode($gtpay_tranx_amt),
        'gtpay_tranx_curr' => urlencode($gtpay_tranx_curr),
        'gtpay_cust_id' => urlencode($gtpay_cust_id),
        'gtpay_tranx_noti_url' => urlencode($gtpay_tranx_noti_url),
        'gtpay_hash' => urlencode($gtpay_hash)
    );


//url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    $form_files=array();
    $form_options=array( 'cookies' => array( 'auth' => $auth ) );
    http_post_fields($url, $fields, $form_files, $form_options);
//open connection
    $ch = curl_init();

//set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//execute post
    $result = curl_exec($ch);

//close connection
    curl_close($ch);

Request made using cURL won't take you to the URL. 使用cURL进行的请求不会将您带到该URL。 It will just process the request and return data back to your end. 它只会处理请求并将数据返回到您的终端。

You need to submit your request using an HTML form with your fields. 您需要使用带有字段的HTML表单提交请求。

Something like this: 像这样:

<form action=" https://ibank.gtbank.com/GTPay/Tranx.aspx" method="post">

<!-- Saved buttons use the "secure click" command -->
<input type="hidden" name="cmd" value="_s-xclick">

<!-- Saved buttons are identified by their button IDs -->
<input type="hidden" name="hosted_button_id" value="221">

<!-- Saved buttons display an appropriate button image. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >

</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确收听 PHP 中的 HTTP JSON POST 请求? - How can I properly listen to HTTP JSON POST requests in PHP? 如何通过 HTTP POST 将 XML 消息发送到测试 URL? - How do I send an XML message via HTTP POST to a test URL? 我如何发送 http get ,从 LARAVEL 发布请求 - How I send http get , post requests from LARAVEL PHP 如何通过 POST 发送 SAFE url 以便在 php 脚本完成后它可以重定向回它来自的页面? - PHP How can I send a SAFE url via POST so that after a php script has finished it can redirect back to the page it came from? 如何防止用户向 php 文件发送如此多的帖子请求 - How can I prevent user to send so many post requests to php file 我该如何在PHP / http post中做到这一点? - How can I do this in PHP / http post? AngularJS-如何使用$ http.post将数据发送到php页面? - AngularJS - how can I send data to the php page with $http.post? 如何使用HTTP POST从Java应用程序发送XML并在服务器上使用PHP打印它? - How can I send XML from a Java application and print it with PHP on the server, using HTTP POST? 如何使用php发送此GCM下游消息(HTTP POST请求)? - How can I send this GCM downstream message (HTTP POST REQUEST) using php? 我需要使用PHP通过HTTP请求使用get变量发送API请求 - I need to send API request using get variables via HTTP requests using PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM