针对HttpWebRequest的HttpWebResponse [英] HttpWebResponse against a HttpWebRequest

查看:72
本文介绍了针对HttpWebRequest的HttpWebResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在创建一个ASP.NET Web项目,其中第三方将击中我的页面之一(使用HTML Form Post),并且我的页面将使用HttpWebRequest POST方法将一些详细信息返回给第三方,第三方将重新发送所有使用关键字接收到的数据,因此我的网站可以确认有效匹配,并向第三方返回有关接收到的POST数据的确认.

此流程类似于付款网关所使用的流程.我的问题是,当我的页面上应该使用什么代码,以便当他们使用以下代码从我的网站获得响应时,流程返回到第三方网页.

Hello All,

I am creating a ASP.NET Web project, where a third party will hit one of my page (using HTML Form Post) and my page will return some details back to the third party using the HttpWebRequest POST method, the third party will resend all the data received with a key word, so my site can confirm the valid hit and return a confirmation to the third party about the POST data received.

This flow is something like used by Payment Gateways. My problem is, what code should be there on my page so the flow returns back to the third party web page, when they are using the following code to get a response from my site.

byte[] post_buffer = Encoding.UTF8.GetBytes(<DataToPost>);

//Create and initialize the request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = post_buffer.Length;
Stream request_stream = request.GetRequestStream();
request_stream.Write(postBuffer, 0, postBuffer.Length);
request_stream.Close();
postBuffer = null;

//send the request, read the response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream response_stream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader read_stream = new StreamReader(response_stream, encode);



EdMan196添加了预块,未选中将我的内容作为纯文本而不是HTML对待"



EdMan196 Edit : Added pre block, unchecked "Treat my content as plain text, not as HTML"

推荐答案

对于任何可能会找的人,请参阅我对原始问题的评论以寻求解决方案.

给OP:请将此标记为已接受的解决方案,以便其他人知道它已解决.

非常感谢,
Ed
For any who may come looking, see my comments on the original question for the solution.

To OP: Please mark this as the accepted solution so that others know it is solved.

Thanks very much,
Ed


这篇关于针对HttpWebRequest的HttpWebResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆