Ask Experts Questions for FREE Help !
Ask
    kim Seoul's Avatar
    kim Seoul Posts: 2, Reputation: 1
    New Member
     
    #1

    Jul 17, 2013, 11:17 AM
    how to find the valid url only
    Hello guys

    I have a project to check out thousands of urls , the problem I'm facing now
    in this code is that I can't handle the out put

    I only need to get message if the url is exists , otherwise I do not want to get any message ;

    her is what I get :
    Response Message OK // if the url is found
    and
    Response Message: Not Found // if the url is not found

    I need to get message only and only if url is found , if it not found I do not wan to
    get any message!

    how to edit down source code in order to make only show message if url is exist and show no thing if url is not exist .
    thank you in advance .


    import java.net.HttpURLConnection;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.UnknownHostException;


    public class URLUtils {

    public static void main(String[] args) {

    URLUtils.checkIfURLExists("https://www.google.co.kr/");





    }

    public static boolean checkIfURLExists(String targetUrl) {
    HttpURLConnection httpUrlConn;
    try {

    httpUrlConn = (HttpURLConnection) new URL(targetUrl)
    .openConnection();



    httpUrlConn.setConnectTimeout(30000);
    httpUrlConn.setReadTimeout(30000);


    System.out.println("Response Message: "
    + httpUrlConn.getResponseMessage());

    return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);



    }
    catch (Exception e) {


    return false;
    }
    }

    }

Check out some similar questions!

Where can I find my computer/company URL account [ 1 Answers ]

I have been asked this question and don't know how to respond

How do I find a url address that has beed used, and view? [ 1 Answers ]

How do I view website with a url address

How do I fix this it keeps popping up! The URL is not valid and cannot be loaded. [ 2 Answers ]

This keeps popping up on my screen when on internet it stops me from visiting other pages. The URL is not valid and cannot be loaded.How do I fix it


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.