Post 特定 URL 的数据并显示 Return 页面

Post Data To A Specific URL & Shows The Return Page

在下面的 HTML 代码中工作正常。

<html>
<head>
<body>
<h1>[http://www.smmotors.org][1]</h1>       

<form name="Redirect_to_NetConnect" method="post"  action="http://www.smmotors.org/NetConnect"> 

<input type="hidden" name="Merchant_ID" value="170922010433235"/>
<input type="hidden" name="Order_No" value="1321"/>
<input type="hidden" name="Order_Amount" value="900.00"/> 
<input type="hidden" name="Date" value="11/09/2017"/>
<input type="hidden" name="Time" value="21:00:00"/>
<input type="hidden" name="CheckSum" value="6217bd46945786a8ab864943e615f2aa"/>
<input type="hidden" name="Transaction_Desc" value="Shop From SM Motors"/>

<input value="try now" type="submit">


</form>
</body>
</head>
</html>

我想在支付插件中显示 return 页面 (Controllers>HomeControllers.cs)

public void NetConnect()
        {
            try
            {

        HttpClient client = new HttpClient();
                var values = new List<KeyValuePair<string, string>>();
                values.Add(new KeyValuePair<string, string>("Merchant_ID", "1709022104222235"));
                values.Add(new KeyValuePair<string, string>("Order_NO", "1321"));
                values.Add(new KeyValuePair<string, string>("Order_Amount", "900.00"));
                //values.Add(new KeyValuePair<string, string>("Date", DateTime.Now.ToString("dd/MM/yyyy")));
                //values.Add(new KeyValuePair<string, string>("Time", DateTime.Now.ToString("HH:mm:ss")));
                values.Add(new KeyValuePair<string, string>("Date", "11/09/2017"));
                values.Add(new KeyValuePair<string, string>("Time", "21:00:00"));

                values.Add(new KeyValuePair<string, string>("CheckSum", checksum));
                values.Add(new KeyValuePair<string, string>("Transaction_Desc", "Shop From SM Motors"));



                var content = new FormUrlEncodedContent(values);

                var response = client.PostAsync("http://http://www.smmotors.org/NetConnect/NetConnect", content).Result;
                var responseString =  response.Content.ReadAsStringAsync();

                var responseString1 = client.GetStringAsync("http://103.25.136.125/KPALServer/NetConnect.aspx");


    }
            catch (Exception)
            {
                throw new Exception();
            }

        }

我 Post 数据到特定 URL 并且想要显示 Return 页面。

在return上面的代码显示空白页。请指导如何显示 return 页面。

好吧,你可以试试这个不太复杂的短代码,它正是你想要实现的目标 添加以下静态 class

public static class Http
{
    public static string Post(string uri, NameValueCollection pairs)
    {
        byte[] response = null;
        using (WebClient client = new WebClient())
        {
            response = client.UploadValues(uri, pairs);
        }
        return System.Text.Encoding.UTF8.GetString(response);
    }
}

然后简单地:

var response = Http.Post("http://103.25.136.125/KPALServer/NetConnect.aspx", new NameValueCollection() {
    { "Merchant_ID", "170900010400235" },
    { "Order_NO", "1321" },
    { "Order_Amount", "900.00" } //similarly include all your post parameters
});
  public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
    {

    string orderNo = postProcessPaymentRequest.Order.Id.ToString();
    string amount = postProcessPaymentRequest.Order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture);
    string merchantId = _NetConnectPaymentSettings.CustomerId;  
    string date = DateTime.Now.ToString("dd/MM/yyyy");
    string time = DateTime.Now.ToString("HH:mm:ss");
    string urlNetConnect = _NetConnectPaymentSettings.PaymentPage;


    string checksum = Generate_MerchantRequest_Check_Sum("7C12B6AECC51A3F3189799098AB1981", merchantId, orderNo, amount, date, time);

    var client = new HttpClient();

    var values = new List<KeyValuePair<string, string>>();
    values.Add(new KeyValuePair<string, string>("Merchant_ID", merchantId));
    values.Add(new KeyValuePair<string, string>("Order_NO", orderNo));
    values.Add(new KeyValuePair<string, string>("Order_Amount", amount));

    values.Add(new KeyValuePair<string, string>("Date", date));
    values.Add(new KeyValuePair<string, string>("Time", time));

    values.Add(new KeyValuePair<string, string>("CheckSum", checksum));
    values.Add(new KeyValuePair<string, string>("Transaction_Desc", "Shop From SM Motors"));


    var content = new FormUrlEncodedContent(values);



    //HttpResponseMessage response = client.PostAsync("http://www.smmotors.org", content).Result;

HttpResponseMessage response = client.PostAsync(urlNetConnect, content).Result;

    if (response.IsSuccessStatusCode)
    {
        var responseString = response.Content.ReadAsStringAsync();


        HttpContext.Current.Response.Write(responseString.Result);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        HttpContext.Current.Response.End();
        _webHelper.IsPostBeingDone = true;

    }
    else
    {
        throw new NopException();
    }


       return;
}