title: URL not accessible in java code
body: <p>A URL which is accessible from the browser gives a 404 respond code when run in java code.</p>
  
  <p>What is the problem??? ..Can anyone explain me about this</p>
  
  <pre><code>public String login(String url) {
          URL targetURL;
          long start = 0;
          long end = 0;
          float difference = 0;
          HttpURLConnection httpURLConnection;
          StringBuffer strbufstatus = new StringBuffer();
          try {
              //Connecting to the url
              targetURL = new URL(url);
  
              start = System.currentTimeMillis();
  
              httpURLConnection = (HttpURLConnection) targetURL.openConnection();
  
              httpURLConnection.setUseCaches(false);
  
              httpURLConnection.setAllowUserInteraction(false);
  
              httpURLConnection.setDoInput(true);
  
              httpURLConnection.setRequestMethod("GET");
  
              httpURLConnection.connect();
  
              //Getting the respond Code
              int responseCode = httpURLConnection.getResponseCode();
  
              strbufstatus.append("Response Code===&gt; " + responseCode + "&lt;br&gt;");
  
              if(responseCode==200){
  
  
              // System.out.println("respondcode===&gt; " + responseCode);
  
              end = System.currentTimeMillis();
  
              //Calculating the response time
  
              difference = (end - start);
  
              difference = difference / 1000;
  
              // System.out.println("Response Time===&gt; " + difference);
  
              strbufstatus.append("Rsponse time===&gt; " + difference + "&lt;br&gt;");
              }
              } catch (IOException ex) {
              if (ex.toString().contains("java.net.UnknownHostException:")) {
  
                  strbufstatus.append(" - UnknownHostException has occured during Httpconnection\n");
              } else if (ex.toString().contains("java.net.MalformedURLException: unknown protocol:")) {
                  strbufstatus.append(" - Unknown Protocol\n");
              } else if (ex.toString().contains("java.net.ConnectException: Connection timed out: connect")) {
                  strbufstatus.append("Connection TimedOut\n");
              } else {
                  strbufstatus.append("IOException has occured during Httpconnection \n");
              }
              ex.printStackTrace();
          }
          System.out.println("Status" +strbufstatus);
          return strbufstatus.toString();
  
  
      }
  </code></pre>