Forum Discussion

abirHajali's avatar
abirHajali
Occasional Contributor
5 years ago

ReadyAPI is not reading a json file

I have a post request in which i attach two files, the first one must be a json file. Using postman, the api works fine but using soap ui it seems like it's not reading the right format. How is it ...
  • Khouloud's avatar
    Khouloud
    4 years ago

    Hello abirHajali,

    Your Content-type in both parts are not well sended

    Instead of Content-Type: application/json; name=***.json you should send Content-Type: application/json;

    My advice is to modify your request and correct Content-type, the way to do it is to use Event handlers (Filtering requests)

    Use: RequestFilter.filterRequest to modify request before sending, this script aim to retreive and enter the correct Content-type

    def bodyPartAttach = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) // get a part by number, it starts with 0
    bodyPartAttach.removeHeader("Content-Type")
    bodyPartAttach.addHeader("Content-Type", "application/json")

     

    Do the same with the second part (index = 1)