关闭

Access Internet

362人阅读 评论(0) 收藏 举报


        //要请求的url
        public string requesturi = "http://search.51job.com/jobsearch/search_result.php";
        //要发送的请求
        public System.Net.HttpWebRequest webrequest;
        //要收到的响应
        public System.Net.HttpWebResponse webreponse;
        //要发送的 cookie
        public CookieCollection cookies = null;
        //send request
        //第一次发送请求,根据工作地点,职位发布日期,职位关键字 得到具体职位的信息
        private ArrayList sendRequest(string jobarea, int issuedate, string keyword)
        {
            #region  准备发送数据
            System.Text.StringBuilder builder = new StringBuilder();
            //构造将要发送的数据
            //工作地点
            builder.Append("postchannel=0000&stype=0&jobarea=" + jobarea);
            //职位发布日期
            builder.Append("&funtype_big=0100&funtype=0100&industrytype=&issuedate=" + issuedate);
            //职位关键字
            builder.Append( "&keywordtype=2&keyword=" + keyword);
            builder.Append( "&curr_page=1");
            //把发送的数据转换成字节
            byte[] sendbyte = System.Text.Encoding.Default.GetBytes(builder.ToString());
           

            //构造一个请求
            System.Net.HttpWebRequest webrequest = System.Net.WebRequest.Create(requesturi) as System.Net.HttpWebRequest;
            //设置发送请求的提交方式
            webrequest.Method = "post";
            //设置HttpReferer 标头
            webrequest.Referer = "http://search.51job.com/jobsearch/default_search.php";
            //设置发送的数据类型
            webrequest.ContentType = "application/x-www-form-urlencoded";
            //设置发送请求数据的长度
            webrequest.ContentLength = sendbyte.Length;
            //添加 cookie
            if (cookies != null)
            {
                webrequest.CookieContainer = new System.Net.CookieContainer();
                webrequest.CookieContainer.Add(cookies);
            }        
            System.IO.Stream postData = webrequest.GetRequestStream();
            postData.Write(sendbyte, 0, sendbyte.Length);
            postData.Close();
            #endregion
            //receive response
            webreponse = webrequest.GetResponse() as System.Net.HttpWebResponse;

            cookies = webreponse.Cookies;

            System.IO.Stream stream = webreponse.GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312"));
            System.Text.StringBuilder sbuilder = new StringBuilder();
            sbuilder.Append(reader.ReadToEnd()); 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20982次
    • 积分:374
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:8篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论