作者: suger
查看: 905|回复: 0
打印 上一主题 下一主题

[讨论] 爬虫语言java

[复制链接]
跳转到指定楼层
楼主
suger 发表于 2020-8-28 17:30:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
查看: 905|回复: 0
[color=rgba(0, 0, 0, 0.87)]import org.apache.commons.httpclient.Credentials;import org.apache.commons.httpclient.HostConfiguration;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpMethod;import org.apache.commons.httpclient.HttpStatus;import org.apache.commons.httpclient.UsernamePasswordCredentials;import org.apache.commons.httpclient.auth.AuthScope;import org.apache.commons.httpclient.methods.GetMethod;import java.io.IOException;public class Main {    # 代理服务器(产品官网 www.16yun.cn)    private static final String PROXY_HOST = "t.16yun.cn";    private static final int PROXY_PORT = 31111;    public static void main(String[] args) {        HttpClient client = new HttpClient();        HttpMethod method = new GetMethod("https://httpbin.org/ip");        HostConfiguration config = client.getHostConfiguration();        config.setProxy(PROXY_HOST, PROXY_PORT);        client.getParams().setAuthenticationPreemptive(true);        String username = "16ABCCKJ";        String password = "712323";        Credentials credentials = new UsernamePasswordCredentials(username, password);        AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT);        client.getState().setProxyCredentials(authScope, credentials);        try {            client.executeMethod(method);            if (method.getStatusCode() == HttpStatus.SC_OK) {                String response = method.getResponseBodyAsString();                System.out.println("Response = " + response);            }        } catch (IOException e) {            e.printStackTrace();        } finally {            method.releaseConnection();        }    }}





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-11-22 18:58, Processed in 0.539921 second(s), 30 queries , Gzip On.

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