You are on page 1of 10

Http and URL

Amira Albadi
2016493059
:URL
URL is one of the key concepts of the Web. It is the
mechanism used by browsers to retrieve any published
.resource on the web
:Example
/http://java.sun.com
file:///Macintosh%20HD/Java/Docs/JDK
%201.1.1%20docs/api/java.net.InetAddress.html#_top
_
http://www.macintouch.com:80/newsrecent.shtml
/ftp://ftp.info.apple.com/pub
mailto:elharo@metalab.unc.edu
telnet://utopia.poly.edu
/ftp://mp3:mp3@138.247.121.61:21000/c%3a/stuff/mp3
/http://elharo@java.oreilly.com
http://metalab.unc.edu/nywc/comps.phtml?
category=Choral+Works
The Pieces of a URL
the protocol
the authority
user info
user name
password
host name or address
port
the path
the ref
the query string
The java.net.URL class
.A URL object represents a URL
The URL class contains methods to
create new URLs
parse the different parts of a URL
get an input stream from a URL so you can read data from
a server
get content from the server as a Java object
Content and Protocol Handlers
Content and protocol handlers separate the data being
.downloaded from the protocol used to download it

The protocol handler negotiates with the server and


parses any headers. It gives the content handler only the
.actual data of the requested resource

The content handler translates those bytes into a Java


.object like an InputStream or ImageProducer
When the virtual machine creates a URL object, it looks for a protocol handler
that understands the protocol part of the URL such as
file
ftp
gopher
http
mailto
appletresource
doc
netdoc
systemresource
verbatim
If no such handler is found, the constructor throws a
.MalformedURLException
Example of URL Methods
import java.net.*;
public class HelloWorld{
     public static void main(String []args){
         try{
             URL ur = new URL("ftp://mp3:mp3@138.247.121.61:21000/c%3a/");
             System.out.println("the Host of this URL:"+ ur.getHost());
             System.out.println("the File of this URL:"+ ur.getFile());
             System.out.println("the port of this URL:"+ ur.getPort());
             System.out.println("the protocol of this URL:"+ ur.getProtocol());
             System.out.println("the refrence of this URL:"+ ur.getRef());
             System.out.println("the Query of this URL:"+ ur.getQuery());
             System.out.println("the Path of this URL:"+ ur.getPath());
             System.out.println("the User Information of this URL:"+ ur.getUserInfo());
             System.out.println("the Authority of this URL:"+ ur.getAuthority());
}
         catch (MalformedURLException e){
       
         }
     }
}

You might also like