|
发表于 2011-1-22 11:33:42
|
显示全部楼层
比如访问网址 http://hy.58.com/danche/ ,它的代码可能就是- private bool Request_hy_58_com(out HttpWebResponse response)
- {
- response = null;
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://hy.58.com/danche/");
- request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 QQDownload/1.7";
- request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
- request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-cn,zh;q=0.5");
- request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
- request.Headers.Set(HttpRequestHeader.AcceptCharset, "GB2312,utf-8;q=0.7,*;q=0.7");
- request.Headers.Add("Keep-Alive", "115");
- request.KeepAlive = true;
- request.Headers.Set(HttpRequestHeader.Cookie, @"id58=902X00yN6PRafhZUYhrSAg==; __utma=253535702.348090455.1284368626.1295331116.1295600481.14; __utmz=253535702.1295331116.13.6.utmcsr=news.qq.com|utmccn=(referral)|utmcmd=referral|utmcct=/zt2010/2011chunyun/; Hm_lvt_84617e905c7416b9895edacb8dbb7ccb=1284432009871; city=hf; www58com=AutoLogin=True&UserID=17246605&UserName=rq204&CityID=483&Email=wddh007%40126.com&MsgReadTotal=0&MsgUnReadTotal=0&AllMsgTotal=0&SystemReadTotal=0&SystemUnReadTotal=0&RequireFriendReadTotal=0&RequireFriendUnReadTotal=0&CommentReadTotal=0&CommentUnReadTotal=0&UserCredit=10&UserScore=0&PurviewID=F&IsAgency=false&Agencys=&SiteKey=08CDD29DF3C9758877EEE3E5CC46D4B5C5B5F9D5736CA5ECD&Phone=&WltUrl=&UserLoginVer=08CDD29DF3C9758870561B84B2BE5BCC3; caipiao=B5D0C5B56295AB0C");
- response = (HttpWebResponse)request.GetResponse();
- }
- catch (WebException e)
- {
- if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
- else return false;
- }
- catch (Exception)
- {
- if(response != null) response.Close();
- return false;
- }
- return true;
- }
复制代码 |
|