如何将帖子数据发送到网址

时间:2013-05-30 06:20:41

标签: c# asp.net .net

我的问题是我必须集成支付网关。我的请求和响应与支付网关一样好。但是这个网关的问题是它只与公共服务器通信。现在我想调试我的后期代码,这取决于支付Gateway的响应。

目前的情况是,

页面 - >支付网关 - > B页

现在我知道支付网关的响应很好所以我只想从A页面发送支付网关的硬编码响应 - > B页面借助HttpWebResponse和POST方法帮助

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();

但它不会将帖子数据发送到我的B页面,以便我可以调试我的B页

1 个答案:

答案 0 :(得分:2)

试试这段代码。

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();