Skip to content

Instantly share code, notes, and snippets.

@sks147
Created September 22, 2016 03:16
Show Gist options
  • Save sks147/8b91131bec9335432f82f769d7983035 to your computer and use it in GitHub Desktop.
Save sks147/8b91131bec9335432f82f769d7983035 to your computer and use it in GitHub Desktop.
Send a request to www server using the HTTP protocol format using GET method.
import java.io.*;
import java.net.*;
import java.util.*;
//Send a request to www server using the HTTP protocol format using GET method
public class GETMethod{
public static void main(String args[]){
URL u = null;
try{
u = new URL("http://www.bbc.co.uk/accessibility/guides/");
HttpURLConnection http = (HttpURLConnection) u.openConnection();
http.setRequestMethod("GET");
System.out.println(u + " was last modified at " + new Date(http.getLastModified()));
}catch (MalformedURLException ex){
System.err.println(u + "is not a well defined url");
}catch (IOException ex){
System.err.println(ex);
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment