Jump to content
WAPT Forum
vprashanth23

How to send a JSON file as body content in POST method of REST call testing?

Recommended Posts

Hi Team,

I have a scenario where i need to test a Post method of REST API.I have all the data required for the request's json body in a file.How to set this file as body for request? Im trying to do somethng like below but im getting code 400 bad request.I tried using multipart data but it is sending content type as body so getting in valid JSON.

image.thumb.png.5e111ec8a42c755eca3f879d13e6d7c8.png

Any help is appreciated.Thanks in advance.

Share this post


Link to post
Share on other sites

Hi,

You have to use the JavaScript operator to read a content from the file. Add to the operator something like the following:

var fso,filehandle,contents;
fso = new ActiveXObject("Scripting.FileSystemObject");
filehandle = fso.OpenTextFile("D:\\Temp\\WAPT\\5.0 Test\\JSONFromFile\\json.txt",1);
contents = filehandle.ReadAll();
log.message(contents);
context.variable("test") = contents;
filehandle.close();

Then use the variable "test" in a POST request body.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...