Forum Discussion

kasia's avatar
kasia
New Contributor
7 months ago

Mismatch between response from a CURL request and ReadyAPI response

Hello, 

I'm encountering a significant issue as I'm receiving an unexpected response when sending a request through ReadyAPI to validate error handling in the software under test. (The request works as expected when it's a 'passing' request).

Here is the curl request :

curl -X POST http://localhost/xxx/api/rest/latest/ai-servers -H 'Authorization: Basic xxx' -d '{"name": "name"}' -H'Content-Type: application/json'

and the correct response:

{"fieldValidationErrors":[{"objectName":"post-ai-server","fieldName":"url","fieldValue":null,"errorMessage":"This attribute can't be empty"}]}

When I send the same request in ReadyAPI I get 

<response null="true"></response>

Could you please tell me what this is due to?

Best regards,

Kasia

  • kasia 

    I see below header sent in curl request.

    Content-Type: application/json

    What did see in the raw tab of the request? Try adding that header and see.

    Otherwise, try adding Accept Header with application/json as value

     

     

     

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    In ReadyAPI, you show a screenshot of the request, after you have clicked 'Send' and got the response, have a look at the Raw tab next to the Request tab.

    The contents of the raw tab show exactly what ReadyAPI passed to the service, but it is only populated after Send is clicked.

    You might be able to spot what is different by comparing Raw request to your Curl request.

    In ReadyAPI, it looks like you're passing {id}, could that be the difference?

  • nmrao's avatar
    nmrao
    Champion Level 3

    kasia 

    I see below header sent in curl request.

    Content-Type: application/json

    What did see in the raw tab of the request? Try adding that header and see.

    Otherwise, try adding Accept Header with application/json as value

     

     

     

    • kasia's avatar
      kasia
      New Contributor

      Thank you!

      The "Content-Type: application/json" header did not work, but the "Accept" did. Do you know why that is? I thought the "Media Type" field was for adding just that... (And it works for the basic request - the one generating the intended response; but does not for the error response...)

      • nmrao's avatar
        nmrao
        Champion Level 3

        Accept head tell the API service that the client wants the response in the given format.