How do I change the http proxy and have the page update?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   James_Cooper
Posted On:   Thursday, November 18, 2004 02:19 AM

I have an app that allows the proxy server to be set. Once it is set it works fine. System.setProperty("http.proxyHost", "proxy"); System.setProperty("http.proxyPort", "80"); I use this code to get the page: String getPage() { URL url = new URL("http://someurl"); URLConnection connection = url.openConnection(); connection.setDoInput(true); connection.setUseCaches(false); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer buff = new StringBuffer(); for (String str = null; (str = in.readLine()   More>>


I have an app that allows the proxy server to be set. Once it is set it works fine.


			
System.setProperty("http.proxyHost", "proxy");
System.setProperty("http.proxyPort", "80");


I use this code to get the page:


			
String getPage() {
URL url = new URL("http://someurl");
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setUseCaches(false);
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer buff = new StringBuffer();
for (String str = null; (str = in.readLine()) != null; ) {
buff.append(str);
}
return buff.toString();
}


If I change the proxy server then the page doesn't update correctly, ie it still seems to use the old proxy server (perhaps cached?) even though I change the System property.


If I go to a different URL then the new proxy works fine, and continues to work even if I go back to the old url.


Is there something I need to flush to make it work? If print the proxy server in the method then it is always giving me the correct answer.


Bear in mind that I never need to keep the url connection open, or cached. I just want to poll a page every few minutes.


Thanks in advance.

   <<Less

Re: How do I change the http proxy and have the page update?

Posted By:   James_Cooper  
Posted On:   Friday, November 19, 2004 07:38 AM

To answer my own question, I cast the UrlConnection to either an HttpURLConnection or an HttpsURLConnection and call disconnect.



Surely there must be a better way that doesn't involve casting?
About | Sitemap | Contact