Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate HTTP PUT request

 
Arpit Purohit
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to generate HTTP PUT request programatically using java.
Can anybody help on this topic.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Jakarta HttpClient. It's free.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Something like the following will do the trick:

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it depends how advanced your usage will be. Plain JDK Java will do for the simplest cases, but Jakarta HTTPClient will help a lot with more-difficult cases.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let's slide this over to the Servlets forum, not sure that's the best place but it's better than here
 
Arpit Purohit
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
let me make it more clear about HTTP PUT request.
It is used to create new resource on server.And same i want to do programatically.
Can anybody give me example for that?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be more specific what you're trying to do? Peter and myself mentioned two possibilities how to send a request from the client side; on the server side you can use a servlet's doPut method. If that doesn't help, tell us where you're stuck implementing this, and we'll try to get you going again.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really a servlets question either (unless you need help with the doPut methdod). Moving to Sockets and Internet Protocols.
 
Arpit Purohit
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being more specific,
I want to create a resource on server by sending PUT request from the client (which is the basic usage PUT request ). I know very well that PUT request is handled on server side (servlet) using doPut() method. But i am not clear about following things:

1. How can i generate PUT request from client (say java program)?
2. Further, how and what to handle on servet's doPut() method so as to create
resource?
3. As known, PUT request is to create resource on server, do i have to provide
resource name(to be created) as parameter in the request and how?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. How can i generate PUT request from client (say java program)?

Paul and I mentioned two ways of doing this. What else are you looking for?

2. Further, how and what to handle on servet's doPut() method so as to create resource?

3. As known, PUT request is to create resource on server, do i have to provide resource name(to be created) as parameter in the request and how?

Conceptually, a PUT is somewhat similar to a POST, with the body of the request containing the resource. So you'd use the Request.getInputStream method to get at the data of the resource.

The name of the resource is the URI (or URL in this case), so no extra name is supplied. You should read section 9.6 of the HTTP specification (and the other sections it points to) for further details regarding the implementation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic