• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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: 1266
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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 ?
 
Jack Mutansan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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.
 
Ranch Foreman
Posts: 1903
12
  • Mark post as helpful
  • send pies
  • 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.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic