sr1991
sr1991

Reputation: 253

RESTful Services - GET and POST requests not working

I am using an example given in RESTful Java client with Jersey client to practice GET and POST requests. I downloaded the code and tried running on Eclipse Neon. I used Tomcat v8.0. But it's not giving the intended output as explained in that demo. The 'GET' request is giving response in JSON format but there is no line as "Output from server...". Am I missing a point here? And when I try 'POST' request, its showing an error HTTP Status 405 - Method Not Allowed. Screenshot is below.

enter image description here

Could anyone help me understand where I am going wrong in this?

Thanks in advance!

Upvotes: 1

Views: 1862

Answers (2)

Stanton
Stanton

Reputation: 495

It would appear that URL only supports GET.

Try:

curl -XPOST http://localhost:8080/RESTfulExample/rest/json/metallica/post

It would appear the GET version of that is (which you can user in your browser):

curl -XGET http://localhost:8080/RESTfulExample/rest/json/metallica/get

Upvotes: 1

Kedar Mhaswade
Kedar Mhaswade

Reputation: 4695

  1. With the HTTP GET request, you are getting what you want. The tutorial means that the line after "Output from Server .... " is what the server sends.

  2. With the HTTP POST request, you should post something using an interface (e.g. Postman extension of Chrome browser, curl command line client etc.). Merely connecting to the POST URL in the browser is not going to actually post anything to the server. Please see Wikipedia on HTTP GET and HTTP POST request.

Upvotes: 0

Related Questions