permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HEAD, DELETE, PUT, OPTIONS, Requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HEAD, DELETE, PUT, OPTIONS, Requests" Watch "HEAD, DELETE, PUT, OPTIONS, Requests" New topic
Author

HEAD, DELETE, PUT, OPTIONS, Requests

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Do anyone of you know how can I trigger this methods?

Thanks in advance.
Ian Perkins
Greenhorn

Joined: Dec 18, 2003
Posts: 19
Hi,
You could try the following:
import java.net.*
public class HttpClient {

public static void main(String[] args) {
URL url = new URL("http://localhost:8080/MyApp/servlet/MyServlet");
URLConnection conn = url.openConnection();
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("HEAD");

httpConn.connect();
// then use various methods to extract response code, headers etc
// for example (j2se 1.4 only)...
Map m = httpConn.getHeaderFields();
}
}
}
I was also looking for a way to send the other method types to a servlet and came across the above in a Sun tech tip. There are a few strange things (like how to pass parameters in a POST) but basically it seems to behave as expected...
HTH
Ivan Matmati
Ranch Hand

Joined: Feb 26, 2003
Posts: 41
You can do it with a telnet client too and no need of a jvm:
example
telnet xxx 8080

if you want more information in different HTTP requests, have a look at the RFC for HTTP.
Good luck.


No Gates!<p>SCPJ 1.4<br />SCWCD 1.4
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
thank you guys! but just one more question, Ivan, I my telnet (windows 2000) does not show any thing in the screen!! is it a problem with my operating system?
Ivan Matmati
Ranch Hand

Joined: Feb 26, 2003
Posts: 41
It's about this devil microsoft!
No, seriously, you have to type :
telnet
prompt > set localecho
reply
prompt > open xxxx yy.

that's all.
Good luck.
 
jQuery in Action, 2nd edition
 
subject: HEAD, DELETE, PUT, OPTIONS, Requests