http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8762|回复: 2

[求助] 关于HttpHelper设置代理访问问题

[复制链接]
发表于 2013-7-23 13:36:01 | 显示全部楼层 |阅读模式
用你的HttpHelper设置代理(110.4.12.171:80)访问下面的网址一直报 The remote server returned an error: (404) Not Found.
http://info.3g.qq.com/g/s?aid=index&from=wap3g&s_it=1&sid=00
不要IP能正常访问
后再自己写了个get方法
  1. public static string SendGetRequest(string Url)
  2. {
  3.     string message = string.Empty;
  4.     try
  5.     {
  6.         HttpWebRequest request = (HttpWebRequest) WebRequest.Create(Url);
  7.         request.Accept = "text/html, application/xhtml+xml, */*";
  8.         request.UserAgent = "Opera/9.80 (Windows NT 5.1; U; zh-cn) Presto/2.10.229 Version/11.61";
  9.         request.KeepAlive = true;
  10.         request.ProtocolVersion = HttpVersion.Version11;
  11.         WebProxy proxy = new WebProxy("110.4.12.171:80");
  12.             request.Proxy = proxy;
  13. ServicePointManager.Expect100Continue = false;
  14.         Stream responseStream = ((HttpWebResponse) request.GetResponse()).GetResponseStream();
  15.         StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
  16.         message = reader.ReadToEnd();
  17.         reader.Close();
  18.         responseStream.Close();
  19.     }
  20.     catch (Exception exception)
  21.     {
  22.         message = exception.Message;
  23.     }
  24.     return message;
  25. }
复制代码
有时也会报The remote server returned an error: (404) Not Found. 但大多数情况下不会报错 求教育
纠结了好久一直没解决


我用java写了个 非常正常都没出现过404


[code=java]public static String sendGetRequest(String reqURL) {
        String responseContent = null;
        DefaultHttpClient httpClient =new DefaultHttpClient();
        HttpHost proxy = new HttpHost("110.4.12.171", 80);
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        HttpGet httpGet = new HttpGet(reqURL);     
        try {
            HttpResponse response = httpClient.execute(httpGet);
            HttpEntity entity = response.getEntity();
            if (null != entity) {
                responseContent = EntityUtils.toString(entity, "UTF-8");
                EntityUtils.consume(entity);
            }
            httpGet.abort();
        } catch (ClientProtocolException e) {
            httpGet.abort();
        } catch (ParseException e) {
            httpGet.abort();
        } catch (IOException e) {
            httpGet.abort();
        } finally {
            httpClient.getConnectionManager().shutdown();
        }
        return responseContent;
    }[/code]

这个代理是多验证的代理 必须用这个代理
求大神帮忙解决 java写的窗体各种不舒服 就帮忙纠结代理问题






1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-7-23 13:55:56 | 显示全部楼层
求苏飞大神帮助
发表于 2013-7-23 14:12:25 | 显示全部楼层
这不是代理问题吧,主要是这两个问题
request.ProtocolVersion = HttpVersion.Version11;

ServicePointManager.Expect100Continue = false;
这个在HttpItem都有参数的你可以直接设置
这样写就行了
[code=csharp]  HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项   
                Method = "get",//URL     可选项 默认为Get   
                Expect100Continue = false,
                ProtocolVersion = HttpVersion.Version11
            };
            HttpResult result = http.GetHtml(item);
            string html = result.Html;[/code]
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-2 20:41

© 2014-2021

快速回复 返回顶部 返回列表