问:我想要在我的页面上发布或执行并在我的同一页面上获取响应,而不是重定向或转到另一个页面我发布的页面。
我创建了一个动态网页表单。
<form id="PostForm" name="PostForm" action="https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm" method="POST">
<input type="hidden" name="merchant_code" value="XYZ">
<input type="hidden" name="encdata" value="+yw5GSwy5ns7XP0/XYZ/6YEkdfjs fjvnsdr+cecGpm0kwhgopO3Jc9RHTld+sj7h6EKm5tcFGN8/oc5yG9E2JfXeboxlkw31bkrD4fXFr0=">
</form>
我想发布请求并使用C#响应这段HTML代码而不在另一页上重定向。
我尝试使用下面提到的代码,但它不是查询字符串的工作值。
public bool SendSMS(string mobileNo, string message)
{
try
{
string strUrl = "https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm.......... SO On...";
WebRequest request = HttpWebRequest.Create(strUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader readStream = new StreamReader(s);
string dataString = readStream.ReadToEnd();
response.Close();
s.Close();
readStream.Close();
return true;
}
catch (Exception)
{
return false;
}
}
他们要求只使用上述表格中的值与帖子方法请尽快建议。
答案 0 :(得分:0)
我收到了此查询的答案。
protected void Page_Load(object sender, EventArgs e)
{
string ForChecksum = string.Format("Sbi_txn_id={2}|arn={0}|amount={1}", "08072016012003001", "1", "1234567890");
DoubleVerificationCheck(ForChecksum.Trim());
}
public string DoubleVerificationCheck(string data)
{
NameValueCollection requestNameValue = new NameValueCollection();
string postData = "encdata=" + data + "|merchant_code=XYZ";
NameValueCollection nameValue = new NameValueCollection();
nameValue.Add("merchant_code", "XYZ");
nameValue.Add("encdata", data);
string responseMsg = PostRequest("https://merchant.Payemtgateway.com/doubleverification.htm", nameValue);
return responseMsg;
}
public static string PostRequest(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
response = client.UploadValues(uri, pairs);
}
return System.Text.Encoding.UTF8.GetString(response);
}