setting content type in rest assured

后端 未结 8 1198
广开言路
广开言路 2021-01-07 21:53

I\'m trying to invoke a rest call using rest assured. My API accepts, \"application/json\" as content type and I need to set in the call. I set the content type

8条回答
  •  离开以前
    2021-01-07 22:48

    I was facing something similar and after some time we noticed the problem was actually coming from the server side. Please check your call on Postman and see if when it's triggered you need to change it from HTML to JSON. If you need to do that, the backend may need to force the response to be in JSON format by adding its content type. Even if it's encoded in JSON you're still may need to do that.

    Thats the line of code we added:

    header('Content-type:application/json;charset=utf-8');
    

    .

      public function renderError($err){
       header('Content-type:application/json;charset=utf-8');
       echo json_encode(array(
           'success' => false,
           'err' => $err
       ));
    }
    

    And that's what was happening on the backend:

    Hope that can help somehow. :)

提交回复
热议问题