从C#中的post方法页面获取页面源代码 [英] Getting page source from post method page in C#

查看:107
本文介绍了从C#中的post方法页面获取页面源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在post方法中获取结果页面源,在第一页中输入并获取结果页面源。实际上它有推荐网址。



i我正在尝试下面的代码,但我得到第一页源代码

i无法获取第二页源代码。





请解决此问题



谢谢。


我尝试过:



I am trying to get result page source in post method , give inputs in first page and get result page source. Actually it have referral url.

i am trying below code but i am getting first page source code
i can not getting second page source code.


please solve this issue

Thank you.

What I have tried:

string strURL = "";
           string strPostData = "";
           string strResult = "";
           HttpWebRequest wbrq = default(HttpWebRequest);
           HttpWebResponse wbrs = default(HttpWebResponse);
           StreamWriter sw = default(StreamWriter);
           StreamReader sr = default(StreamReader);
           strURL = "http://cbseresults.nic.in/aieee/cbseaieee.asp";
           strPostData = string.Format("regno", "20616948");
           wbrq = WebRequest.Create(strURL);
           wbrq.Method = "POST";
           wbrq.Referer = "http://cbseresults.nic.in/aieee/cbseaieee.asp";
           wbrq.ContentLength = strPostData.Length;
           wbrq.ContentType = "application/x-www-form-urlencoded";
           StreamWriter sw= new StreamWriter(wbrq.GetRequestStream);
            sw.Write(strPostData);
            sw.Close();
            wbrs = wbrq.GetResponse();
            StreamReader sr = new StreamReader(wbrs.GetResponseStream);
            strResult = sr.ReadToEnd().Trim();
            sr.Close();
            richTextBox1.Text = strResult;

推荐答案

引用:

strPostData = string.Format("regno", "20616948");



如果调试你的代码,你会看到 string.Format 调用的结果是文字字符串regno



这不是一个有效的 application / x-www-form-urlencoded 正文。



我认为你的意思是:


If you debug your code, you'll see that the result of that string.Format call is the literal string "regno".

That is not a valid application/x-www-form-urlencoded body.

I assume you meant:

strPostData = "regno=20616948"


这篇关于从C#中的post方法页面获取页面源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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