将数据从控制器发送到外部URL
本文关键字:外部 URL 数据 控制器 | 更新日期: 2023-09-27 17:49:54
我正在为一家公司实现支付系统,并使用3D安全模型。基本上,我需要向银行发布如下数据:
<form method="post" action="https://<sunucu_adresi>/<3dgate_path>">
....
</form>
和银行返回一些值?我怎么能张贴到这个URL从控制器采取返回参数?
致意。
可能的解决方案#1和问题(@elolos)
这是我在NewPayment控制器中的2个动作。我正在调用http://localhost.com:34324/NewPayment/PostTo3D,但得到404错误。我不知道async函数实际上,我认为这404是关于我的错?我应该如何调用这个async函数?
[HttpPost]
public ActionResult umut(string bb) {
ViewBag.Message = bb;
return View();
}
[HttpPost]
private async Task<HttpResponseMessage> PostTo3D()
{
HttpClient client = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("bb", "Hello Worlds")
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
return await client.PostAsync("http://localhost.com:34324/NewPayment/umut", content);
}
try this
var url = "http://www.somepaymentprovider.com";
Response.Clear();
var sb = new System.Text.StringBuilder();
sb.Append("<html>");
sb.AppendFormat("<body onload='document.forms[0].submit()'>");
sb.AppendFormat("<form action='{0}' method='post'>", url);
sb.AppendFormat("<input type='hidden' name='now' value='{0}'>", strId);
sb.AppendFormat("<input type='hidden' name='random' value='{0}'>", random);
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");
Response.Write(sb.ToString());
Response.End();
你可以使用HttpClient类,这里有一个简单的例子:
[HttpPost]
private async Task<HttpResponseMessage> PostTo3D()
{
HttpClient client = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("someField", "value")
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
return await client.PostAsync("https://<sunucu_adresi>/<3dgate_path>", content);
}