2 Replies Latest reply on Aug 31, 2020 3:34 PM by Tu Nguyen

    Creating POST handler with Content-Type:application/json

    Tu Nguyen

      Hi everyone,

       

      I'm trying to build an REST service from ORDS for receving data from other applications. They send POST request with "Content-Type:application/json" Headers, and this is fixed.

       

      Problem is when calling my service, ORDS returns "400 bad request". I tried to test this with Postman without  "Content-Type:application/json" and the service is just fine.

       

      So how do we config ORDS to receive such header?

        • 1. Re: Creating POST handler with Content-Type:application/json
          EJ-Egyed

          I am able to reproduce this issue as well on ORDS 19.2.  If you submit a POST request and the request header has "Content-Type: application/json" it seems that ORDS is attempting to validate that the body of the request is JSON, but it is doing a very poor form of validation.  It seems to only be checking that the request body begins with { or [.  I don't believe there is a way to disable this validation. Is the application that is calling your API ever sending an empty request body or a request body that doesn't begin with { or [? (leading white space does not seem to be an issue)

           

          All the screenshots below are using the "Content-Type: application/json" header:

           

          No Body:

           

          Valid JSON:

           

          Invalid JSON, but body begins with { still functions properly.

          • 2. Re: Creating POST handler with Content-Type:application/json
            Tu Nguyen

            Yes you are right. The problem is because of empty body or it doesn't begin with "{"

             

            Thank you so much.