Skip to main content
 首页 » 编程设计

c#之POST 或 GET 方法

2024年02月20日18rubylouvre

我们有一个服务提供商,允许我们连接到他的支付页面进行支付,但是他使用的代码是 php,但我们想在 asp.net 中进行。

问题是我不太明白方法应该是什么,POST 或 GET,基本上我们需要使用底层参数(不是查询字符串)重定向到客户端) 然后我们调用请求的当前页面也必须使用参数重定向到客户端页面。

我确实收到基本上是标记的响应,但这不是我想要的,我希望它重定向到付款页面,有人可以告诉我我做错了什么吗。谢谢 这是我用于 POST 方法的代码:

string query = string.Format("description={0}&amount={1}&merchantIdent={2}&email={3}&transaction={4}&merchantKey={5}", 
                             description.ToString(), amount.ToString(), merchantIdent.ToString(), email.ToString(), id.ToString(), merchantKey.ToString()); 
 
// Create the request back 
string url = "https://www.webcash.co.za/pay"; 
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 
 
req.Method = "POST"; 
req.AllowAutoRedirect = true; 
req.ContentType = "application/x-www-form-urlencoded"; 
req.ContentLength = query.Length; 
req.AllowAutoRedirect = true; 
 
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),System.Text.Encoding.ASCII); 
stOut.Write(query); 
stOut.Close(); 
 
// Do the request 
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); 
string response = stIn.ReadToEnd(); 
stIn.Close(); 

请您参考如下方法:

不确定我是否完全理解您的问题,但正如您的标题所说,这是 POST 和 GET 之间的区别: GET 方法通过 url 传递变量。这可能是实际的或不切实际的(例如,如果您打算将敏感 Material 传递到另一个页面) POST 方法不通过 url 传递变量,它在后台传递变量。 您需要决定哪个更适合您的情况。