Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

POST Variables come in Request Body  RSS feed

 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a third-party application, that when I do a POST, the variables come into the Java web service in the Request body.

Yet, using POSTMAN and the same URL (and POST, did not set any headers), the Request variables come into the service as expected (not in the Request body).

So, I'm now wondering if how software products do a POST is up to a particular vendor or if I'm missing something?

I worked around this issue by handing the POST both ways: (1) If the variables are in the Request body and (2) if the variables can be gotten via request.getParameter....

Thanks in advance for any guidance on this issue.

- mike
 
Stephan van Hulst
Saloon Keeper
Posts: 7707
141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it depends on the client. However, you should not support both. In general, you should only use query string parameters for GET and HEAD requests.

For your POST requests, Postman adds a Body tab. That's where you should put your parameters.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Yes, it depends on the client. However, you should not support both. In general, you should only use query string parameters for GET and HEAD requests.

For your POST requests, Postman adds a Body tab. That's where you should put your parameters.


So, for POST, it's pretty much normal to have to extract the parameters from the Request body then.

That's interesting and still a bit confusing.

I've attached the POSTMAN screenshot showing how I set up the POST.

In the WS, it said "POST" but I was able to read the variables using parameter methods.

- mike
postman-POST.png
[Thumbnail for postman-POST.png]
 
Stephan van Hulst
Saloon Keeper
Posts: 7707
141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea is that the URL identifies certain information that you're interested in, and the request body provides data to perform a certain action.

Let's say you used a query string to identify a user of your application:

Now, let's say I wanted to update my profile information. I would still use the same URL to identify my profile, but I would use the request body to provide the data that's needed to perform the update action:
Parameter nameParameter value
fullNameStephan van Hulst

fullName is NOT needed to identify the resource I want to update, so it goes into the request body, NOT the query string.
 
Ron McLeod
Saloon Keeper
Posts: 1561
222
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally:
  • the body should be used to carry the resource/entity representation - request body for POST and PUT, response body for GET
  • HTTP headers should be used for metadata for a transaction such as the format used to represent the resource carried in the body, any encodings, compression, etc. - for example: how the resource represented - JSON, XML, CSV, etc.
  • query parameters should be used for information which might be used to further specify a resource or group of resources (in addition to the URI path) - for example: selection criteria for a GET, or maybe a base template for a resource in a POST
  •  
    Mike London
    Ranch Hand
    Posts: 1441
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephan van Hulst wrote:The idea is that the URL identifies certain information that you're interested in, and the request body provides data to perform a certain action.

    Let's say you used a query string to identify a user of your application:

    Now, let's say I wanted to update my profile information. I would still use the same URL to identify my profile, but I would use the request body to provide the data that's needed to perform the update action:
    Parameter nameParameter value
    fullNameStephan van Hulst

    fullName is NOT needed to identify the resource I want to update, so it goes into the request body, NOT the query string.


    I think you mean userName from your POST URL abpve, but I see what you're saying.

    In the Java stuff I've done with POST, I get the parameters in the Servlet using "request.getParameter(....)", not from the body.

    So, if in a JSP page I have a form submit with POST, in the POSTed-to Servlet, I have always used request.getParameter() to extract the POSTed parameters.

    Maybe you're making a separate point?

    Thanks,

    - mike

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7707
    141
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mike London wrote:I think you mean userName from your POST URL abpve, but I see what you're saying.

    No, I meant fullName. userName IS needed to identify the resource, so it goes in the URL. fullName IS NOT, so it goes in the request body.

    In the Java stuff I've done with POST, I get the parameters in the Servlet using "request.getParameter(....)", not from the body.

    Read the documentation for getParameter(). It retrieves parameters from both the query string and the request body.

    So, if in a JSP page I have a form submit with POST, in the POSTed-to Servlet, I have always used request.getParameter() to extract the POSTed parameters.

    Yes that's fine if you're using bare servlets, but many MVC frameworks require you to carefully design your API by specifying if a parameter should be a query or a form parameter.
     
    Mike London
    Ranch Hand
    Posts: 1441
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephan van Hulst wrote:
    Mike London wrote:I think you mean userName from your POST URL abpve, but I see what you're saying.

    No, I meant fullName. userName IS needed to identify the resource, so it goes in the URL. fullName IS NOT, so it goes in the request body.

    In the Java stuff I've done with POST, I get the parameters in the Servlet using "request.getParameter(....)", not from the body.

    Read the documentation for getParameter(). It retrieves parameters from both the query string and the request body.

    So, if in a JSP page I have a form submit with POST, in the POSTed-to Servlet, I have always used request.getParameter() to extract the POSTed parameters.

    Yes that's fine if you're using bare servlets, but many MVC frameworks require you to carefully design your API by specifying if a parameter should be a query or a form parameter.


    I guess without knowing more about the FileMaker POST implementation, I'll be happy with getting the POST variables from the request body. (The methods that get those variables from the request parameters return null). And, when using POSTMAN, per my image above with the indicated parameters, then the body is empty and the request parameters work.

    Thanks for all your help!!!

    -- mike
     
    Ron McLeod
    Saloon Keeper
    Posts: 1561
    222
    Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you want to really know how FileMaker or Postman is providing the data, try using a network sniffer such as Wireshark and see exactly what is being sent over the wire.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7707
    141
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mike London wrote:And, when using POSTMAN, per my image above with the indicated parameters, then the body is empty and the request parameters work.

    Like I said, when you use POST with Postman, a Body tab appears where you can specify form parameters. These will go into the request body. You can use a combination of query parameters and form parameters.
     
    Mike London
    Ranch Hand
    Posts: 1441
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephan van Hulst wrote:
    Mike London wrote:And, when using POSTMAN, per my image above with the indicated parameters, then the body is empty and the request parameters work.

    Like I said, when you use POST with Postman, a Body tab appears where you can specify form parameters. These will go into the request body. You can use a combination of query parameters and form parameters.


    Got it, thanks.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!