-
Make an HTTP connection from a Java standalone application (8 messages)
- Posted by: Sorin Cristescu
- Posted on: June 07 2006 07:33 EDT
Hello, What would be a simple way to make an HTTP connection to a website from a standalone Java application and to check if the response code is 200 (success) ? Thank you, SorinThreaded Messages (8)
- Re: Make an HTTP connection from a Java standalone application by Guillaume Grussenmeyer on June 07 2006 09:09 EDT
- Re: Make an HTTP connection from a Java standalone application by Guillaume Grussenmeyer on June 07 2006 09:12 EDT
-
Thanks, it seems I have another issue by Sorin Cristescu on June 07 2006 10:26 EDT
-
using HttpURLConnection from behind a firewall by Kamati Pura on June 07 2006 05:58 EDT
-
Re: using HttpURLConnection from behind a firewall - still wrong by Sorin Cristescu on June 09 2006 06:21 EDT
-
Re: using HttpURLConnection from behind a firewall - still wrong by Guillaume Grussenmeyer on June 09 2006 07:55 EDT
- Sorry, my fault by Sorin Cristescu on June 09 2006 09:11 EDT
-
Re: using HttpURLConnection from behind a firewall - still wrong by Guillaume Grussenmeyer on June 09 2006 07:55 EDT
-
Re: using HttpURLConnection from behind a firewall - still wrong by Sorin Cristescu on June 09 2006 06:21 EDT
-
using HttpURLConnection from behind a firewall by Kamati Pura on June 07 2006 05:58 EDT
-
Thanks, it seems I have another issue by Sorin Cristescu on June 07 2006 10:26 EDT
- Re: Make an HTTP connection from a Java standalone application by Guillaume Grussenmeyer on June 07 2006 09:12 EDT
- my solution is... by Vlad Patryshev on January 04 2012 14:33 EST
-
Re: Make an HTTP connection from a Java standalone application[ Go to top ]
- Posted by: Guillaume Grussenmeyer
- Posted on: June 07 2006 09:09 EDT
- in response to Sorin Cristescu
Use HTTPClient : http://jakarta.apache.org/commons/httpclient/ -
Re: Make an HTTP connection from a Java standalone application[ Go to top ]
- Posted by: Guillaume Grussenmeyer
- Posted on: June 07 2006 09:12 EDT
- in response to Guillaume Grussenmeyer
Ooops may be a little bit to heavy for your need. Simply use an HttpURLConnection : http://java.sun.com/j2se/1.5.0/docs/api/java/net/HttpURLConnection.html -
Thanks, it seems I have another issue[ Go to top ]
- Posted by: Sorin Cristescu
- Posted on: June 07 2006 10:26 EDT
- in response to Guillaume Grussenmeyer
Thanks Guillaume, I'm using an HttpURLConnection and I get an java.net.UnknownHostException in the line "if ...." (see below). Is it because I'm behind a firewall ? And if so, how can I solve this ? Thank you, Sorin // example urlString: "http://www.yahoo.com" URL url = new URL(urlString); //Get an input stream for reading InputStream in = url.openStream(); urlConnection = (HttpURLConnection)url.openConnection(); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader (new InputStreamReader(urlConnection.getInputStream())); } -
using HttpURLConnection from behind a firewall[ Go to top ]
- Posted by: Kamati Pura
- Posted on: June 07 2006 17:58 EDT
- in response to Sorin Cristescu
If you are behind a firewall, you need to have the proxyHost and proxyPort variables set as follows: http.proxyHost=webcache http.proxyPort=8080 https.proxyHost=webcache https.proxyPort=8080 You can do this by using the command line flag -D or by using calls to System.setProperty(). -
Re: using HttpURLConnection from behind a firewall - still wrong[ Go to top ]
- Posted by: Sorin Cristescu
- Posted on: June 09 2006 06:21 EDT
- in response to Kamati Pura
Thank you Ajay. So I do the following: System.setProperty("http.proxyHost", "webcache"); System.setProperty("http.proxyPort", "8080"); System.setProperty("https.proxyHost", "webcache"); System.setProperty("https.proxyPort", "8080"); .... and then my original code: URL url = new URL(newUrlString.toString()); urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.connect(); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader (new InputStreamReader(urlConnection.getInputStream())); } ... and I get the same error (java.net.UnknownHostException) at the line: urlConnection.connect(); If I remove this line, I get the error at urlConnection.getResponseCode(). What am I doing wrong ? Thank you, Sorin -
Re: using HttpURLConnection from behind a firewall - still wrong[ Go to top ]
- Posted by: Guillaume Grussenmeyer
- Posted on: June 09 2006 07:55 EDT
- in response to Sorin Cristescu
Did you replace 'webcache' and '8080' by the hostname and port of your proxy server ? Did you check that the host your URL relates to is reachable from your computer ? -
Sorry, my fault[ Go to top ]
- Posted by: Sorin Cristescu
- Posted on: June 09 2006 09:11 EDT
- in response to Guillaume Grussenmeyer
Guillaume, you're perfectly right. I forgot to use my proxy server. Now it works. Thanks a lot, Sorin -
my solution is...[ Go to top ]
- Posted by: Vlad Patryshev
- Posted on: January 04 2012 14:33 EST
- in response to Sorin Cristescu
Use my ClientHttpRequest from myjavatools.com