I am having following groovy code that makes a post call to get some auth token and it works fine:
def post = new URL("abc.com").openConnection();
def message = '{"username":"user", "password":"pass"}'
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
println(postRC);
if (postRC.equals(200)) {
println(post.getInputStream().getText());
}
I now what to make a new post call multipart/form data where i will pass auth token in header and a file in form data. The curl call for the same (generated by postman), looks like follow:
curl --location --request POST 'abc.com/resources' \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: token' \
--form 'request=@"myfile.yaml"'
Now if i modify the above url request in groovy to support this curl call, i can add content-type in post.setRequestProperty("Content-Type", "multipart/form-data") and same for auth token, how can I set form data in this with request key = file ?