Go – 重定向到特定的URL并携带有效载荷

huangapple go评论88阅读模式
英文:

Go - redirect to specific url with payload

问题

我正在尝试在我的应用程序中实现支付方法,需要帮助。

为了显示支付页面,我需要向他们的URL执行POST请求,并附带支付负载。通常,他们会响应一个HTML响应,然后我需要将其渲染到屏幕上。然而,我得到的是一个错误,说会话无效。

我的问题是:是否可能使用POST和请求负载重定向到另一个URL?

POST http://payment.api.net/merchant/init?corpid=CN000001
<order>
    <corp>NN01</corp>
    <amount>20.0</amount>
    <currency>USD</currency>
    <ordernumber>10010111</ordernumber>
    <redirect>http://mycallback.api.net/store/payment/callback</redirect>
    <randomstring>NnwLRINzhOgvmvyunzZIrUtCgvmvy</randomstring>
    <hash>4792e72f5e1860b220420ad3f22f005c9d2fce83f3a138336869780153145700</hash>
</order>
英文:

I'm trying to implement payment method on my application, and I need help.

To show the payment page, I need to perform POST request to their url with a payment payload. Normally they will response with a html response, and after that I need to render it to screen. However, what I got is an error saying that session is invalid.

My question: is it possible to redirect to another url with POST and a request payload?

POST http://payment.api.net/merchant/init?corpid=CN000001
&lt;order&gt;
    &lt;corp&gt;NN01&lt;/corp&gt;
    &lt;amount&gt;20.0&lt;/amount&gt;
    &lt;currency&gt;USD&lt;/currency&gt;
    &lt;ordernumber&gt;10010111&lt;/ordernumber&gt;
    &lt;redirect&gt;http://mycallback.api.net/store/payment/callback&lt;/redirect&gt;
    &lt;randomstring&gt;NnwLRINzhOgvmvyunzZIrUtCgvmvy&lt;/randomstring&gt;
    &lt;hash&gt;4792e72f5e1860b220420ad3f22f005c9d2fce83f3a138336869780153145700&lt;/hash&gt;
&lt;/order&gt;

答案1

得分: 1

请尝试使用以下代码:

<html>
	<body>
		<form action="http://payment.api.net/merchant/init?corpid=CN000001" method="post" enctype='text/plain'>
			<input type="hidden" name="order" value="<order><corp>NN01</corp><amount>20.0</amount><currency>USD</currency><ordernumber>10010111</ordernumber><redirect>http://mycallback.api.net/store/payment/callback</redirect><randomstring>NnwLRINzhOgvmvyunzZIrUtCgvmvy</randomstring><hash>4792e72f5e1860b220420ad3f22f005c9d2fce83f3a138336869780153145700</hash></order>">
			<button type="submit">Submit</button>
		</form>
	</body>
</html>

希望这能解决你的问题。

英文:

Try to use this code..

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;html&gt;
	&lt;body&gt;
	&lt;form action=&quot;http://payment.api.net/merchant/init?corpid=CN000001&quot; method=&quot;post&quot; enctype=&#39;text/plain&#39;&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;order&quot; value=&#39;&lt;order&gt;&lt;corp&gt;NN01&lt;/corp&gt;&lt;amount&gt;20.0&lt;/amount&gt;&lt;currency&gt;USD&lt;/currency&gt;&lt;ordernumber&gt;10010111&lt;/ordernumber&gt;&lt;redirect&gt;http://mycallback.api.net/store/payment/callback&lt;/redirect&gt;&lt;randomstring&gt;NnwLRINzhOgvmvyunzZIrUtCgvmvy&lt;/randomstring&gt;&lt;hash&gt;4792e72f5e1860b220420ad3f22f005c9d2fce83f3a138336869780153145700&lt;/hash&gt;&lt;/order&gt;&#39;&gt;
		&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
	&lt;/form&gt;
	&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

May it solve your problem..

huangapple
  • 本文由 发表于 2016年8月24日 20:17:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/39123113.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定