在下面的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>
我想在付款插件中显示退货页面(Controllers&gt; 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();
}
}
我将数据发布到特定网址&amp;想要显示返回页面。
作为回报,上面的代码显示空白页面。请指导如何显示返回页面。
答案 0 :(得分:0)
那么你可以尝试这个简短的代码,它不那么复杂,而且正是你想要实现的目标 添加以下静态类
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
});
答案 1 :(得分:0)
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;
}