事实上,这是一个更一般的问题,但现在我正试图在wordpress网站上使用它,所以我更愿意把它贴在这里。
我试图理解远程post和表单post之间的区别。
当我查询一个字符串并将其发布到远程服务器时,我得到的结果是字符串,并使用“print$response”在浏览器控制台上查看它。但我希望它在浏览器上显示为html。我是在期待错误的事情还是我会做这样的事情?
基本上,我希望将原始响应视为html。
EDIT
以防更具表现力。。我正试图在woocommerce内部编写信用卡支付网关
在客户订单结束时调用的process\\u payment函数中,我将所有信息发布到银行服务器,如下所示:
public function process_payment( $order_id ) {
global $woocommerce;
....
...
$okUrl = "http://localhost/xxx/wc-api/paymentpos/";
$failUrl = "http://localhost/xxx/wc-api/paymentpos/";
$payload = array(.....);
$response = wp_remote_post( $environment_url, array(
\'method\' => \'POST\',
\'body\' => http_build_query( $payload ),
\'timeout\' => 45,
\'sslverify\' => false,
) );
$respbody = wp_remote_retrieve_body($response);
print $respbody;
}
之后,银行服务器应该回复payment\\u callback(),如下所示
public function payment_callback(){
global $woocommerce;
wc_add_notice( \'OK\', \'success\' );
.....
exit();
}
我在控制台上得到如下$respbody。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript">
function moveWindow() {
document.returnform.submit();
}
</script>
</head>
<body onLoad="javascript:moveWindow()">
<form action="http://localhost/xxx/wc-api/paymentpos/" method="post" name="returnform">
<input type="hidden" name="EXTRA.ERTELEMESABITTARIH" value="20121123">
....
<input type="hidden" name="okUrl" value="http://localhost/xxx/wc-api/paymentpos/">
...
<input type="hidden" name="mdStatus" value="2">
<input type="hidden" name="HASH" value="QZVV9Zfv4tlzi36WJNbLVlbuWY8=">
<input type="hidden" name="rnd" value="GSZV87rHM+Ol5WDiMbtC">
<input type="hidden" name="HASHPARAMS" value="clientid:oid:AuthCode:ProcReturnCode:Response:mdStatus:cavv:eci:md:rnd:">
<input type="hidden" name="HASHPARAMSVAL" value="100200000160451Declined2499850:FE7D7E1062435636DEA77FD3F96CE40C68334FAFE6458F2FC530F26814B29935:4043:##100200000GSZV87rHM+Ol5WDiMbtC">
...
<!-- To support javascript unaware/disabled browsers -->
<noscript>
<center><br>
Please Click to continue.<br>
<input type="submit" name="submit" value="Submit" id="btnSbmt"></center>
</noscript>
</form>
</body>
</html>
{"result":"failure","messages":"","refresh":"false","reload":"false"}
此响应应触发payment\\u callback()函数。手动触发payment\\u callback(),如
http://localhost/xxx/wc-api/paymentpos/. 但这种反应无法触发。我怀疑我是否能正确处理wp\\u remote\\u post响应。