如何使用c#获取带有值的html源代码 [英] how to get html source code with values using c#

查看:92
本文介绍了如何使用c#获取带有值的html源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp网页包含2个文本框,我将运行该页面,我将在这些文本框中输入一些数据之后我将点击按钮存储该页面的完整源代码以及文本框值但现在我没有获取文本框值...如何获取这些值以及源代码..?

这里是我的代码..



 HttpWebRequest request =(HttpWebRequest)WebRequest.Create(url); 
HttpWebResponse response =(HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null ;
if (response.CharacterSet == null
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream,Encoding.GetEncoding(response。字符集));
sourcecode = readStream.ReadToEnd();
response.Close();
readStream.Close();
}





请帮帮我

解决方案

< blockquote>如果我读你就对了,你不能这样做。



我认为你要做的是在浏览器中打开一个网站,让用户填写表单详细信息,然后通过从服务器创建页面的新请求来保存页面,包括用户输入的表单详细信息。



那不是怎么回事网站工作:在正常情况下,在用户完成输入之前,没有用户数据从浏览器发送到服务器,并且发送回服务器(通常通过单击按钮)。即便如此,它将在您在此处创建的WebRequest的不同会话中,以便两组输入(如服务器所见)不会相互冲突。



试一试:打开浏览器窗口,填写表格。打开第二个浏览器窗口(或选项卡)并以不同方式填写相同的表单。这两个版本是独立的,因为它们位于不同的会话中(除非表单/服务器使用cookie来存储数据,这对于购物篮来说很常见,因为你需要它们之间的公共数据)。



我不确定你想用这个来实现什么,但我认为你完全走错了路线来实现它!


i have one asp web page contains 2 text boxes,i will run that page and i will enter some data in those text boxes after that i will click button to store complete source code of that page along with text box values but now im not getting text box values...how to get those values along with source code..?
here is my code..

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         if (response.StatusCode == HttpStatusCode.OK)
         {
             Stream receiveStream = response.GetResponseStream();
             StreamReader readStream = null;
             if (response.CharacterSet == null)
                 readStream = new StreamReader(receiveStream);
             else
                 readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
             sourcecode = readStream.ReadToEnd();
             response.Close();
             readStream.Close();
         }



please help me

解决方案

If I read you right, you can't do that.

What I think you are trying to do is open a website in your browser, have the user fill in the form details, then save the page including the form details the user entered by creating a new request for the page from the server.

That isn't how websites work: under normal circumstances, no user data is sent from the browser to the server until the user completes his input an initiates a post-back to the server (normally by clicking a button). Even then, it will be in a different session to the WebRequest you create here so that the two sets of input (as the server sees it) do not conflict with each other.

Try it: Open a browser window, fill in a form. Open a second browser window (or tab) and fill in the same form differently. The two versions are independent because they are in different sessions (unless the form / server uses cookies to store the data, as is common for shopping baskets because you want common data between them).

I'm not sure what you are trying to achieve with this, but I think you are going down totally the wrong route to achieve it!


这篇关于如何使用c#获取带有值的html源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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