关于.NET技术.. 求火车头技术人员帮帮我!!
#region 获取远程文件源代码/// <summary>
/// 获取远程文件源代码
/// </summary>
/// <param name="url">远程url</param>
/// <param name="EnCodeType">编码</param>
/// <returns></returns>
public string GetHttpPageCode(string Url, Encoding EnCodeType)
{
string strResult = string.Empty;
if (Url.Length < 10)
return "$UrlIsFalse";
try
{
//WebClient MyWebClient = new WebClient();
//MyWebClient.Credentials = CredentialCache.DefaultCredentials;
//MyWebClient.Encoding = EnCodeType;
//strResult = MyWebClient.DownloadString(Url);
string rl;
WebRequest myReq = WebRequest.Create(Url);
WebResponse myRes = myReq.GetResponse();
Stream resStream = myRes.GetResponseStream();
StreamReader sr = new StreamReader(resStream, EnCodeType);
StringBuilder sb = new StringBuilder();
while ((rl = sr.ReadLine()) != null)
{
sb.Append(rl);
}
strResult = sb.ToString();
myRes.Close();
}
catch (Exception)
{
strResult = "$GetFalse";
}
return strResult;
}
#endregion
采集地址为:http://hy.58.com/danche/
问题:采集得到的STRING 根本不是原来的源文件..
求版主或会的朋友..救下我..为什么..为什么只有58网的列表我取不了!! 把你调用代码贴出来..还有就是注意你编码传入的值是否与网站一样..... 比如访问网址 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;
} - -收藏下..、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
页:
[1]