急求解通过代理服务器访问internet资源遇到的问题!

nhisense nhisense 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有些公司的http代理服务器需要身份验证,包括域名、用户名、密码等信息。
我使用如下方式,但是总不能成功。希望各位大哥指点:
(http代理服务器不需要身份验证的时候可以通过) 代码如下:
public class Post {
public Post() {
}
public static void main(String[] args) throws Exception{
Post post1 = new Post();
Properties prop = System.getProperties();

prop.put( "http.proxySet", "true" );
prop.put( "http.proxyHost", "10.1.2.13" );
prop.put( "http.proxyPort", "80" );
// prop.put( "http.auth.ntlm.domain", "wonders_files" );

prop.put( "http.proxyType", "4");

String urlstring = "http://www.sina.com.cn/";
String parameters = "name=value1&age=value2";

URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setRequestProperty("Proxy-Authorization","Basic mydomain\\username:password");
conn.setRequestMethod("GET");

conn.connect(); // throws IOException
InputStream input = conn.getInputStream();
File file = new File("D:/420/sina.html");
FileOutputStream fos = new FileOutputStream(file);
byte[] b = new byte[8192];
int count = 0;
while(true){
if((count=input.read(b))==-1) break;
fos.write(b,0,count);
}
fos.close();
}
}

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
nhisense
Web 开发 81,108 成员 341,721 内容