Reputation: 1007
I am trying to write @POST sync method which will take in 2 String parameters. When I access the 2 links from the browser, I did not get the return String "SUCCESS!". It seems the methods doesn't get called at all?
http://localhost:9080/SampleWeb/resources/helloworld/sync?param1=string1¶m2=string2
http://localhost:9080/SampleWeb/resources/helloworld/sync/string1/string2
@Path("/helloworld")
public class HelloWorldResource {
@POST
@Produces("text/plain")
@Path("/sync")
public String sync(
@QueryParam("param1") String param1,
@QueryParam("param2") String param2) {
//do something
return "SUCCESS!";
}
@POST
@Produces("text/plain")
@Path("/sync/{param1}/{param2}")
public String sync(
@PathParam("param1") String param1,
@PathParam("param2") String param2) {
//do something
return "SUCCESS!";
}
}
Upvotes: 0
Views: 209
Reputation: 141
If you are trying to access the URL directly from the browser you will access the GET method. To access other HTTP methods you can use some browser plugins that act like REST Clients, for example, I use RESTClient Firefox plugin. There you can supply other options like Request Body and other useful options like HTTP Headers as Content-type: application/json.
Upvotes: 0
Reputation: 8127
You said you're accessing the links from a browser - are you "browsing" to the URL, or are you explicitly POSTing to the URL from a form submit (or using javascript)? If you're just "browsing" to the link (i.e. clicking the link or putting it in the address bar), your browser will perform a GET, not a POST.
If you're using a Unix OS or have curl installed on Windows, you can use curl to perform the POST, and you should receive the "SUCCESS!" response:
curl -X POST http://localhost:9080/SampleWeb/resources/helloworld/sync?param1=string1
Upvotes: 1