network programming - Java program does not connect to internet? -
this program compiles when try run program gives me errors.
import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.filewriter; import java.io.inputstreamreader; import java.net.url; public class main { public static void main(string[] args) throws exception { url url = new url("http://www.google.com"); bufferedreader reader = new bufferedreader (new inputstreamreader(url.openstream())); bufferedwriter writer = new bufferedwriter (new filewriter("data.html")); string line; while ((line = reader.readline()) != null) { system.out.println(line); writer.write(line); writer.newline(); } reader.close(); writer.close(); } }
the following error occurs (i have attached image):
i behind proxy server. make problem in connecting internet? if please post solution .. in advance.
you should similar:
1st of put proxy information system properties:
system.getproperties().put( "proxyset", "true" ); system.getproperties().put( "proxyhost", "proxy_hostname" ); system.getproperties().put( "proxyport", "8080" ); // or other proxy port
and need authentication on proxy, using similar:
url url = new url("http://www.google.com"); urlconnection con = url.openconnection(); string pass = "my_username:my_pass"; string encodedpass = base64encode( pass ); con.setrequestproperty( "proxy-authorization", encodedpass );
good luck.
Comments
Post a Comment