如何发送Post数据到url

本文关键字:url 数据 Post 何发送 | 更新日期: 2023-09-27 18:16:15

我的问题是,我必须整合支付网关。我的请求和回应罚款与支付网关。但该网关的问题是只能与公共服务器通信。现在我想调试我的后期代码,这取决于支付网关的响应。

当前场景是,

A page -> payment Gateway -> B page

现在我知道支付网关的响应是好的,所以我想通过HttpWebResponse与POST方法的帮助从A页发送硬编码的支付网关响应,

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redirectUrl);
request.Method = "POST";
string formContent = "data";    
byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);            
dataStream.Close();

但是它不发送post数据到我的B页所以我可以调试我的B页

如何发送Post数据到url

试试下面的代码。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redirectUrl);
    request.Method = "POST";
    string formContent = "data";   
    byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
    requestWriter.Write(byteArray);            
    requestWriter.Close();
    dataStream.Close();