url = new URL( path );
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
InputStream in = httpConn.getInputStream();如果要通过代理出去,可以设置:
private String socksProxyHost = "202.119.24.34"; //default socks proxy
private String socksProxyPort = "1080"; //default socks port
private String httpProxyHost = "211.167.0.131"; //default http proxy
private String httpProxyPort = "80"; //default http portSystem.getProperties().setProperty( "socksProxyHost",socksProxyHost );
System.getProperties().setProperty( "socksProxyPort",socksProxyPort );
System.getProperties().setProperty( "http.proxyHost",httpProxyHost );
System.getProperties().setProperty( "http.proxyPort",httpProxyPort );
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
InputStream in = httpConn.getInputStream();如果要通过代理出去,可以设置:
private String socksProxyHost = "202.119.24.34"; //default socks proxy
private String socksProxyPort = "1080"; //default socks port
private String httpProxyHost = "211.167.0.131"; //default http proxy
private String httpProxyPort = "80"; //default http portSystem.getProperties().setProperty( "socksProxyHost",socksProxyHost );
System.getProperties().setProperty( "socksProxyPort",socksProxyPort );
System.getProperties().setProperty( "http.proxyHost",httpProxyHost );
System.getProperties().setProperty( "http.proxyPort",httpProxyPort );
我想用一个对话框,主要用户输入一个URL地址(比如: http://www.google.com/images/logo.gif),就可以打开这幅图片,我用尽了我所知的办法,就是不能实现,好心的大哥大姐们,快救救我啊!
因为我不知道socks proxy 和socks port 怎么设置.
我用你给我的:
System.getProperties().setProperty( "http.proxyHost",httpProxyHost );
System.getProperties().setProperty( "http.proxyPort",httpProxyPort );你的这个设置只能在jdk1.4.2以上的情况下才用,而且要在进行
URL resource = new URL("http://www.google.com/images/logo.gif");
resource.openStream()
的操作之前设置才有用.
在做了一次resource.openStream()操作之后再设置的话,即使再去做N次resource.openStream()的操作也是无效!
请问这是为什么? 怎样做能够在做了一次resource.openStream()操作之后再设置,还能够取的这个数据流?
当然应该在Open之前设置,这个还用讨论?import java.net.*;
import java.io.*;public class TestHttp { public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "your_proxy_ip");
System.setProperty("http.proxyPort", "1080");
URL resource = new URL("http://www.google.com/intl/zh-CN/");
InputStream is = resource.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
URL resource = new URL("http://www.google.com/images/logo.gif");
resource.openStream();
... ...
System.getProperties().setProperty( "http.proxyHost",httpProxyHost );
System.getProperties().setProperty( "http.proxyPort",httpProxyPort );
... ...
resource.openStream();
resource.openStream();不能成功,为什么?????????我想在不知道是代理式访问时先作常规的操作,在不能访问后,提示要设置代理,但是我这样做行不通啊! 在怎么办???
open之前必须要能访问。没有设代理,你怎么能访问到呢?