C# 显示发布到 iframe 的结果
您好,
我正在使用此方法在 C# 中执行一篇文章。
string post1(string url, string postdata)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//byte[] byteArray = Encoding.UTF8.GetBytes(s);
byte[] byteArray = Encoding.ASCII.GetBytes(postdata);
var x = byteArray.ToString();
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
string resp = (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
return(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
}
其中 postdata 就像
string postData = "login=" + HttpUtility.UrlEncode("xxxxxx") +
// "&password=" + HttpUtility.UrlEncode("yyyyy");
我得到的响应是一些 html。
现在的问题是我想在 iframe 中显示请求,但我不知道如何执行此操作。
这也是发表帖子并在 iframe 中显示页面的正确方法还是我应该看看不同的东西..?我使用 asp.net 3.5 和 c#
谢谢
HI
I am perfoming a post in c# using this method.
string post1(string url, string postdata)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//byte[] byteArray = Encoding.UTF8.GetBytes(s);
byte[] byteArray = Encoding.ASCII.GetBytes(postdata);
var x = byteArray.ToString();
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
string resp = (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
return(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
}
where postdata is like
string postData = "login=" + HttpUtility.UrlEncode("xxxxxx") +
// "&password=" + HttpUtility.UrlEncode("yyyyy");
The response i get back is some html.
NOw the problem is i want to show the request in an iframe but i have no clue as to how to do so..
Also is this the right way to do a post and show the page in an iframe or should i look at something differen.. ? Im using asp.net 3.5 and c#
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否有特定原因需要在 iframe 内进行此操作?另外,什么页面事件触发了这个?回发、AJAX 调用等?
我感觉任何将其推到 iframe 的尝试都会很丑陋,因为 iframe 的设计是不同的资源请求。因此,根据我们目前掌握的信息,我想说将其放入 iframe 中的“最佳”方法是拥有两个页面,即父页面和框架页面。框架页面可能会在
Page_Load
上发出此请求,并将结果显示为其整个响应。但接下来的问题就变成了如何获取该页面所需的数据。父页面很可能在呈现时拥有该数据,对吗?如果是这种情况,那么您可以将其包含在 iframe 的
src
的查询字符串中,然后从框架页面上的查询字符串中读取它。Is there a specific reason why this needs to happen inside of an iframe? Also, what page event is triggering this? A post-back, an AJAX call, etc.?
I get the feeling that any attempt to shove this off to an iframe is going to be ugly because an iframe is by design a different resource request. So, given the information we have so far, I'd say that the "best" way to put this in an iframe would be to have two pages, the parent page and the framed page. The framed page would make this request, possibly on
Page_Load
, and display the results as its entire response.But then the question becomes how to get to that page the data that it needs. In all likelihood the parent page has that data when it's being rendered, correct? If that's the case then you could include it on the query string for the iframe's
src
and then read it from the query string on the framed page.