4 Replies Latest reply on Feb 1, 2019 12:11 PM by Conor Lynch

    POST - JSON value working in CURL, not in Chrome

    Conor Lynch

      Hi there,

      I am developing with Oracle Jet using their CRUD example.

      I am passing in this JSON with valid values. But the variable costsetid is null by the time it gets to the the PLSQL procedure.

      This works with CURL and Boomerang, but not in Chrome or Firefox.

      {"costsetid":"A8","costsetname":"DA8"}

       

      The only response I am getting is my message which fails because the field is null

      {

      "failure":"create_cost_set av_costsetid is null"

      }

       

      This handler is defined below.

      I'm using lowercase parameters in my latest attempt to get this to work.

      Does anyone know of any reason why a JSON parameter would work in CURL and Boomerang and not in Chrome?

       

       

        ORDS.DEFINE_HANDLER(

            p_module_name    => 'cost_sets',

            p_pattern        => 'cost_set_list/',

            p_method         => 'POST',

            p_source_type    => 'plsql/block',

            p_items_per_page =>  0,

            p_mimes_allowed  => '',

            p_comments       => NULL,

            p_source         =>

      'BEGIN

          ws_cost_sets.create_cost_set(av_costsetid       =>  :costsetid,

                                                           av_costsetdescr    =>  :costsetname);

      END;'

      );

       

      Thanks in advance,

      Conor.

        • 1. Re: POST - JSON value working in CURL, not in Chrome
          Olafur T

          Hi,

          Are you sure that Chrome is sending the POST body? If you open up developer console (F12) --> Network and view the POST request.

           

          What is the Request header -> content-type

          What is the Request Payload?

           

           

          You can try piping out the request for debugging purposes:

           

          begin

            ORDS.DEFINE_HANDLER(p_module_name    => 'cost_sets',

                                p_pattern        => 'cost_set_list/',

                                p_method         => 'POST',

                                p_source_type    => 'plsql/block',

                                p_items_per_page => 0,

                                p_mimes_allowed  => '',

                                p_comments       => null,

                                p_source         => 'BEGIN

             /* ws_cost_sets.create_cost_set(av_costsetid => :costsetid,

                                           av_costsetdescr => :costsetname);*/

          htp.prn(:body_text);

          END;');

          end;

           

           

          If you don't have ORDS 18.3+, cast :BODY into a CLOB and print that.

           

          Regards

          Oli

          • 2. Re: POST - JSON value working in CURL, not in Chrome
            Conor Lynch

            Thanks for that.

            Just in case I checked the ORDS version and we are on 3.0.9.348.07.16.

             

            I added the body_text and other references to the define_handler.

            The :body is populated with the JSON but the :body_text is null. Is that correct?

            Also the request and response from Chrome are below.

             

            Thanks again,

            Conor.

             

              ORDS.DEFINE_HANDLER(

                  p_module_name    => 'cost_sets',

                  p_pattern        => 'cost_set_list/',

                  p_method         => 'POST',

                  p_source_type    => 'plsql/block',

                  p_items_per_page =>  0,

                  p_mimes_allowed  => '',

                  p_comments       => NULL,

                  p_source         =>

            'BEGIN

             

                ws_cost_sets.create_cost_set(av_costsetid       =>  :costsetid,

                                             av_costsetdescr    =>  :costsetname);

             

            insert into cl_temp_clob(myclob) values(:body_text);

            commit;

             

            htp.p(''content_type=''||:content_type);

            htp.p(''current_user=''||:current_user);

            htp.p(''fetch_offset=''||:fetch_offset);

            htp.p(''fetch_size=''||:fetch_size);

            htp.p(''row_offset=''||:row_offset);

            htp.p(''row_count=''||:row_count);

            htp.p(''forward_location=''||:forward_location);

            htp.p(''status_code=''||:status_code);

             

            END;'

                  );

             

             

            REQUEST

              1. Request Method: POST
              2. Status Code: 200 OK
              3. Remote Address: 172.20.80.41:8888
              4. Referrer Policy: no-referrer-when-downgrade
            1. Response Headersview source
              1. Cache-Control: no-store
              2. Connection: Keep-Alive
              3. Content-Language: en
              4. Content-Type: application/json
              5. Date: Thu, 31 Jan 2019 15:52:32 GMT
              6. Expires: Sun, 27 Jul 1997 13:00:00 GMT
              7. Keep-Alive: timeout=5, max=100
              8. Pragma: no-cache
              9. Server: Oracle-Application-Server-11g
              10. Transfer-Encoding: chunked
              11. X-DB-Content-length: 201
              12. X-Powered-By: Servlet/2.5 JSP/2.1
            2. Request Headersview source
              1. Accept: application/json, text/javascript, */*; q=0.01
              2. Accept-Encoding: gzip, deflate
              3. Accept-Language: en-US
              4. Connection: keep-alive
              5. Content-Length: 38
              6. Content-Type: application/vnd.oracle.adf.resource+json
              7. Host: dev11gapp:8888
              8. Origin: http://dev11gapp:8888
              9. Referer: http://dev11gapp:8888/dev/conor/oraclejet/coremill_costsets/index.html?root=maint_costset
              10. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
            3. Request Payloadview source
                1. {costsetid: "A8", costsetname: "DA8"}
                  1. costsetid: "A8"
                  2. costsetname: "DA8"

            RESPONSE

            {

            "failure":"create_cost_set av_costsetid is null"

            }

            content_type=application/vnd.oracle.adf.resource+json

            current_user=

            fetch_offset=

            fetch_size=

            row_offset=

            row_count=

            forward_location=

            status_code=

            • 3. Re: POST - JSON value working in CURL, not in Chrome
              Olafur T

              :body_text comes in ORDS 18.3, so you are using a pretty old version, 3.0.9 is from December, 2016. But you still have access to :body which is a BLOB, just need to cast it to CLOB or varchar2.

               

              Can you change "application/vnd.oracle.adf.resource+json" to "application/json"? ORDS can automatically map form data, multipart and application/json, it's probably not doing anything with that content type.

               

              Oli

              • 4. Re: POST - JSON value working in CURL, not in Chrome
                Conor Lynch

                That worked.

                I used the Oracle Jet example

                https://www.oracle.com/webfolder/technetwork/jet-300/jetCookbook.html?component=crud&demo=table

                 

                and when I changed

                          contentType: 'application/vnd.oracle.adf.resource+json',

                  to

                          contentType: 'application/json',

                it worked!

                 

                Thanks for the genius help,

                Conor.