标题:C#带参数的请求
只看楼主
yimaoqian198
Rank: 4
等 级:业余侠客
帖 子:108
专家分:287
注 册:2010-5-10
结帖率:100%
 问题点数:0 回复次数:3 
C#带参数的请求
图入附件所示,如何发送请求,让选择200以后再apply,然后得到html
搜索更多相关主题的帖子: html 200 如何 
2012-07-25 15:04
yimaoqian198
Rank: 4
等 级:业余侠客
帖 子:108
专家分:287
注 册:2010-5-10
得分:0 
怎么没有人回复呢?我想获取pubmed网站上的数据,由于URL被隐藏,不能获得,我想通过每页显示的数量,来获取数据,网址是http://www.ncbi.nlm.nih.gov/pubmed?linkname=pubmed_pubmed&from_uid=1,大家要是有别的办法,帮忙介绍一下,分数照给
2012-07-25 15:14
yimaoqian198
Rank: 4
等 级:业余侠客
帖 子:108
专家分:287
注 册:2010-5-10
得分:0 
问题解决了,利用Fiddler2获取cookie,然后找出变化的数据,带着变化的数据去访问,怎么感觉说不清楚呢,直接上代码
程序代码:
 public static void SendInfo(string postData, string infoUrl, CookieContainer myCookieContainer)
        {
            byte[] byteArray = Encoding.GetEncoding("GBK").GetBytes(postData);
            try
            {

                //发出对url的请求
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(infoUrl);
                httpWebRequest.Timeout = 3000000;
                httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.15 Safari/536.5";
                httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                //得到cookie
               // httpWebRequest.CookieContainer = myCookieContainer;
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            

                //协议方式
                httpWebRequest.Method = "POST";
               
                //与internet建立持久连接
                httpWebRequest.KeepAlive = true;
                //post开始
                //请求内容长度
                httpWebRequest.ContentLength = byteArray.Length;
                Stream dataStream = httpWebRequest.GetRequestStream();
                // 请求数据放入请求流
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
                //返回html
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                if (httpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    string gid = "";

                    StreamReader reader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("GBK"));
                    //读取响应流
                    string responseFromServer = reader.ReadToEnd();//这里是获得的html
                   
                    reader.Close();
                    dataStream.Close();
                    httpWebResponse.Close();


                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }
2012-07-26 10:49
yimaoqian198
Rank: 4
等 级:业余侠客
帖 子:108
专家分:287
注 册:2010-5-10
得分:0 
来个接分的
2012-07-26 10:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-374089-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.199097 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved