将数据从Controller发布到外部URL

时间:2014-03-13 12:21:27

标签: c# asp.net asp.net-mvc

我正在为公司实施支付系统,并使用3D安全模型。基本上,我需要将数据发布到银行,如下所示:

<form method="post" action="https://<sunucu_adresi>/<3dgate_path>">
                ....
</form>

银行正在回归一些价值观?如何从控制器发布到此URL以获取返回参数?

的问候。

可能的解决方案#1和问题(@elolos)

这是我在NewPayment控制器中的2个操作。 我打电话给http://localhost.com:34324/NewPayment/PostTo3D,但收到404错误。我实际上不知道异步功能,我认为这404是关于我的错?我应该如何调用这个异步函数?

    [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);

    }

2 个答案:

答案 0 :(得分:1)

试试这个

 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();

答案 1 :(得分:1)

您可以使用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);

}