• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Restful POST and GET (different result from web and Postman)

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Above is a simple method in a @RestController.  I found when I access this via a browser "http://localhost:8080/xxx/getStudent?classID=2" it works but only works when RequestMethod is "GET".  if I change it to "Post" it doesn't work on browser

However, the interesting thing is, when I use Google Postman tool,  when I specify "GET", I don't get the list of names, but when I use "POST" I get the results (same results as I use "GET" on browser).

Does anybody know why it behaves differently ?
Thanks
 
Bartender
Posts: 1330
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you specify GET method with @Requestmapping, the Rest endpoint will respond only to GET requests. Are you really sure you are POSTing a request???
What happens using curl - for example ?
 
David Mutansan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Claude Moore wrote:If you specify GET method with @Requestmapping, the Rest endpoint will respond only to GET requests. Are you really sure you are POSTing a request???
What happens using curl - for example ?



Hi, I thought I was supposed to use "GET" since this is getting student name.  So it works fine when you use "GET" and view it from URL on a browser.  

What confused me was --- When I use Postman tool, when I specify "GET" I couldn't get results.  But when I specify "POST" it returns data.  I don't understand why.
 
Bartender
Posts: 2265
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jack,
Could you post your code on Github and let us run it ?
GET is to retrieve data.
POST is to add data.

If you want to add (post) data in Postman, you may need to add a request body.

But since your getStudent method is a GET method, using POST will run into an error.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic