简体   繁体   中英

Unable to read payload from File

i am trying to insert payload from jsonfile but getting an bad request and unable to read date from the file, not sure what i am doing wrong

File jsonBody =new File(".\\JSONFileinput\\file.json");
        Response resp=given().header("Content-Type","application/json")
        
        .body(jsonBody)
        .log()
        .all()
        .post("https://restful-booker.herokuapp.com/booking");

    
    resp.prettyPrint();

Use jackson objectMapper objectMapper.writeValue(new File(".\JSONFileinput\file.json"), jsonBody); or writeValueAsString

Read json as a String and the pass it to your body:

String payload = Files.readString(".\\JSONFileinput\\file.json", StandardCharsets.US_ASCII);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM