如何在使用html发布表单将数据发布到外部服务器后提取php响应查询字符串?
页面:delivery.php
<form name="form2" method="post" action="http://dev.site.com/pay/transactionresult" id="form1">
<input type="hidden" value="<?php echo $amt;?>" name="amt" />
<input type="hidden" name="merchant" value="abc">
<input type="hidden" name="orderid" value="<?php echo $orderid;?>">
<input type="hidden" name="referenceid" value="<?php echo $referenceid;?>">
<input type="submit" value="submit"/>
</form>
我认为结果是xml,因为开发人员指南显示了
响应
<response>
<response_code>
success
</response_code>
</response>
<response>
<response_code>
failure
</response_code>
</response>
如何获得回应?请用代码显示。响应代码可以在delivery.php
中吗?
如果你想处理对远程服务器发布的响应,你必须在服务器端执行发布,而不是通过客户端(浏览器(。
这样的想法就是:
client --POST--> your server --response--> client
| ^
POST |
| response
V |
remote server
因此,您向用户显示一个页面,用户可以在其中填写所需的数据,然后将其发布到服务器上的表单处理程序页面。该处理程序页面可以向远程服务器发出请求,并解析响应,从而为客户端生成适当的答案。
例如,您可以使用CURL在服务器端进行远程请求。
例如:(基于其他SO答案的CURL示例(
<?php
if (empty($_POST['amt'])) {
// show form
} else {
$data = ...; // collect and filter data from form
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://remote.example.com/transaction");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") {
// parse $server_output
$message = 'success';
} else {
$message = 'error';
}
// show $message to user
}
?>
这个例子并不完整,但希望能给你一个想法。
我觉得你只是在学习编程,但你想使用http://www.resellerclub.com/domain-reseller/api向客户销售产品。
一种选择是让客户提交一份直接提交给经销商俱乐部的表格,但他们的退货并不那么友好。另一种选择是让你的用户向你的服务器提交一份表格,然后你的服务器向经销商俱乐部网站发出请求。(通过CURL(你会收到经销商俱乐部的回复(强烈建议使用http JSON选项!(,你可以对这些数据做任何你喜欢的事情(通常向网站用户提供回复,感谢他们的提交(
要做到这一点,您必须将表单action=
更改为action="darrens_server.com/payment_submission.php"
,在该php文件中,您可以向经销商俱乐部提交内容,等待响应,并将结果回显给网站用户。
我会说,如果涉及信用卡,这可能不是最好的方法。一般来说,我不处理信用卡交易,我希望有一家货币公司为我做这件事(例如贝宝(。我不需要承担出现问题的责任,也不需要公司里的任何人都能看到用户的信用卡号。在这种情况下,整个处理过程实际上取决于经销商俱乐部网站。你需要遵守他们的规则。
祝你好运。
将此表单提交到外部服务器后,响应将发送到浏览器,而不是服务器。