浏览 4270 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-08-06
最后修改:2011-08-06
/** * 获取Client对象实例并设置http代理 * @return Client * @throws Exception */ public Client getClient() throws Exception { String proxyHost = "代理ip"; String proxyPort = "代理端口"; System.getProperties().put("proxySet", "true"); System.getProperties().put("proxyHost", proxyHost); System.getProperties().put("proxyPort", proxyPort); Client client = new Client(new URL(URL));//URL为你要调用的地址 client.setProperty(client.getOutChannel().USERNAME, "代理上的用户名"); client.setProperty(client.getOutChannel().PASSWORD, "代理上的密码"); // client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "300"); client.setProperty(CommonsHttpMessageSender.DISABLE_KEEP_ALIVE, "true"); client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "true"); client.setProperty(CommonsHttpMessageSender.HTTP_PROXY_HOST, "代理ip"); client.setProperty(CommonsHttpMessageSender.HTTP_PROXY_PORT, "代理端口"); client.setProperty(CommonsHttpMessageSender.HTTP_PROXY_USER, "代理上的用户名"); client.setProperty(CommonsHttpMessageSender.HTTP_PROXY_PASS, "代理上的密码"); return client; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |