Activity Forums Salesforce® Discussions What is the difference between HTTP Post and HTTP GET in Salesforce apex?

  • Prachi

    Member
    July 18, 2018 at 10:51 am

    Hello Anurag,

    GET- In an HTTP GET request, key/value pairs are specified in the URL

    GET requests can be cached
    GET requests remain in the browser history
    GET requests can be bookmarked
    GET requests should never be used when dealing with sensitive data
    GET requests have length restrictions
    GET requests should be used only to retrieve data

    POST -  HTTP POST data is not visible in the URL, and when submitting data to a website.

    POST requests are never cached
    POST requests do not remain in the browser history
    POST requests cannot be bookmarked
    POST requests have no restrictions on data length

     

  • madhulika shah

    Member
    September 14, 2018 at 9:34 am

    Hi Anurag,

    The GET method is meant for data retrieval only and should not have any side-effects. But POST is meant for that specific purpose: altering data on the server side.

    GET requests can easily be forged (see Cross-Site Request Forgery) by just placing an image on a page while forging POST requests is not that easy (this is also a reason why you should only allow authorized POST requests).

    Thanks.

  • Parul

    Member
    September 21, 2018 at 10:45 am

    hi

    HTTP POST:

    POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers.

    GET requests can easily be forged (see Cross-Site Request Forgery) by just placing an image on a page while forging POST requests is not that easy (this is also a reason why you should only allow authorized POST requests).

     

     

  • Avnish Yadav

    Member
    September 21, 2018 at 12:38 pm

    Hello Anurag,

    In both POST and GET you can use parameters in URL.
    The one major and simple difference I will say is the payload (Data/records etc as JSON) which can be passed as a response body in POST where as in GET it is not allowed

    Thanks.

  • shariq

    Member
    September 21, 2018 at 1:35 pm

    Hi,

    HTTP GET:

    GET is idempotent: it is for obtaining a resource, without changing anything on the server. As a consequence it should be perfectly safe to resubmit a GET request.

     

    HTTP POST:

    POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers.

    The official HTTP RFC specifies POST to be:

    Annotation of existing resources;
    Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
    Providing a block of data, such as the result of submitting a form, to a data-handling process;
    Extending a database through an append operation.

    Thanks

Log In to reply.

Popular Salesforce Blogs