J
junk1
Im having problems with the following code...
URL url;
Properties sysProps = System.getProperties();
sysProps.put( "proxySet", "true" );
sysProps.put( "proxyHost", "192.168.211.17");
sysProps.put( "proxyPort", "80" );
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("userid",
"password".toCharArray()));
}};
Authenticator.setDefault(authenticator);
try {
url = new
URL("http://www.realtime-traffic.info/rtt/loadMap.do?gridcode=GR05&textonly=true");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.connect();
System.out.println("con.getResponseCode():[" + con.getResponseCode()
+ "]");
System.out.println("con:[" + con + "]");
System.out.println("con.getContentLength():[" +
con.getContentLength() + "]");
System.out.println("con.getContent():[" + con.getContent() + "]");
InputStream inputStream = con.getInputStream();
StringBuffer trafficData = new StringBuffer();
for (int n = 0; n < con.getContentLength(); n++) {
trafficData.append((char) inputStream.read());
}
System.out.println("trafficData:[" + trafficData + "]");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
.....it gives me a response code of 200. What does 200 mean? And why
wont it connect to the URL?
It works fine If I point it at localhost.
I copied the Authenticator bit from another post, is it the correct way
to do proxy authentication?
Thanks
David Bevan
http://www.davidbevan.co.uk
URL url;
Properties sysProps = System.getProperties();
sysProps.put( "proxySet", "true" );
sysProps.put( "proxyHost", "192.168.211.17");
sysProps.put( "proxyPort", "80" );
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("userid",
"password".toCharArray()));
}};
Authenticator.setDefault(authenticator);
try {
url = new
URL("http://www.realtime-traffic.info/rtt/loadMap.do?gridcode=GR05&textonly=true");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.connect();
System.out.println("con.getResponseCode():[" + con.getResponseCode()
+ "]");
System.out.println("con:[" + con + "]");
System.out.println("con.getContentLength():[" +
con.getContentLength() + "]");
System.out.println("con.getContent():[" + con.getContent() + "]");
InputStream inputStream = con.getInputStream();
StringBuffer trafficData = new StringBuffer();
for (int n = 0; n < con.getContentLength(); n++) {
trafficData.append((char) inputStream.read());
}
System.out.println("trafficData:[" + trafficData + "]");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
.....it gives me a response code of 200. What does 200 mean? And why
wont it connect to the URL?
It works fine If I point it at localhost.
I copied the Authenticator bit from another post, is it the correct way
to do proxy authentication?
Thanks
David Bevan
http://www.davidbevan.co.uk