Java Reference
In-Depth Information
+ new Date ( http . getLastModified ()));
} catch ( MalformedURLException ex ) {
System . err . println ( args [ i ] + " is not a URL I understand" );
} catch ( IOException ex ) {
System . err . println ( ex );
}
System . out . println ();
}
}
}
Here's the output from one run:
$ java LastModified http://www.ibiblio.org/xml/
http://www.ibiblio.org/xml/ was last modified at Tue Apr 06 07:45:29 EDT 2010
It wasn't absolutely necessary to use the HEAD method here. You'd have gotten the same
results with GET . But if you used GET , the entire file at http://www.ibiblio.org/xml/ would
have been sent across the network, whereas all you cared about was one line in the
header. When you can use HEAD , it's much more efficient to do so.
DELETE
The DELETE method removes a file at a specified URL from a web server. Because this
request is an obvious security risk, not all servers will be configured to support it, and
those that are will generally demand some sort of authentication. A typical DELETE
request looks like this:
DELETE /javafaq/2008march.html HTTP/1.1
Host: www.ibiblio.org
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: close
The server is free to refuse this request or ask for authorization. For example:
HTTP/1.1 405 Method Not Allowed
Date: Sat, 04 May 2013 13:22:12 GMT
Server: Apache
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Length: 334
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method DELETE is not allowed for the URL
/javafaq/2008march.html.</p>
<hr>
<address>Apache Server at www.ibiblio.org Port 80</address>
</body></html>
Search WWH ::




Custom Search