Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Trying to get a simple java program running. Whenever I try this code though I get a Exception in thread "main" java.lang.IllegalStateException: connect in progress
Here is the code.
public class Checker404
public static int getResponseCode(String urlString) throws MalformedURLException, IOException
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.connect();
huc.setRequestMethod("HEAD");
huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
huc.disconnect();
return 1;
public static void main(String[] args) throws Exception
final String URL = "http://www.asda.com";
Checker404.getResponseCode(URL);
I've tried changing around the huc.connect to before the request property and requestMethod, it will just compile but not do anything. But when it is like this I get the connect in progress error. Any advice would be welcome. I am a bit new to programming so forgive any inconsistencies I have.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.