您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Java >> 大家帮忙看一下 高分相送~~

大家帮忙看一下 高分相送~~

来源:网络整理     时间:2016/8/12 9:28:21     关键词:

关于网友提出的“ 大家帮忙看一下 高分相送~~”问题疑问,本网通过在网上对“ 大家帮忙看一下 高分相送~~”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 大家帮忙看一下 高分相送~~
描述:

大家好,我现在想基于代理服务器做一个网页爬虫程序,使用的是apache开源下的import org.apache.http.client.HttpClient;但现在遇到一个问题,希望各位大虾帮助,多少分都可以,只要能帮我解决这个问题 ~~
我参考的是一下网址的例子,通过代理访问网页。
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
但遇到的问题是我随便写代理服务器的地址,也仍然能抓取到网页的内容,本机是不需要代理上网的。是我理解有问题还是参数设置有问题呢 大家帮忙,谢谢啦
--------------------------------------------------------------------------------------------------------------------
 // make sure to use a proxy that supports CONNECT
        HttpHost target = new HttpHost("issues.apache.org", 443, "https");
        HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");//我就是更改的该类的第一个参数,应该是这样的吧,如果是更改代理服务器的设置的话。
  //下面的部分就是基本的设置然后读取网页内容了,我理解应该没有问题吧 嘿嘿
      // general setup
        SchemeRegistry supportedSchemes = new SchemeRegistry();
        // Register the "http" and "https" protocol schemes, they are
        // required by the default operator to look up socket factories.
        supportedSchemes.register(new Scheme("http", 
                PlainSocketFactory.getSocketFactory(), 80));
        supportedSchemes.register(new Scheme("https", 
                SSLSocketFactory.getSocketFactory(), 443));
        // prepare parameters
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpProtocolParams.setUseExpectContinue(params, true);
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, 
                supportedSchemes);
        DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        HttpGet req = new HttpGet("/");
        System.out.println("executing request to " + target + " via " + proxy);
        HttpResponse rsp = httpclient.execute(target, req);
        HttpEntity entity = rsp.getEntity();
-----------------------------------------------------------------------------------------------------------------------------------
大家帮帮忙啊  送多少分都可以~~


以上介绍了“ 大家帮忙看一下 高分相送~~”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3222044.html

相关图片

相关文章