import http from 'k6/http'
import {check} from 'k6'
import {Trend} from 'k6/metrics'
import { sleep } from 'k6'
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { SharedArray } from 'k6/data';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
var token;
let doc = open('./try.pdf');
export const options =
{
scenarios: {
booking_patch: {
executor: 'ramping-vus',
startVUs: 0,
stages: [ { duration: '1s', target: 1 },
{ duration: '2s', target: 1 },
]
}}
};
export default function () {
// Getting a random id
let ID=randomIntBetween(1,100000000000);
const posturl = `https://dummy.com/doc/${ID}`;
const fd = new FormData();
let doc={
prod:'Dull',
do:'boo',
}
let docjson = JSON.stringify(doc);
fd.append('d', http.file(doc, 'try.pdf','application/pdf'));
fd.append('docum',docjson);
// const data = {}
// calling the post api
const res = http.post(posturl,fd.body(), { headers:
{
'Content-Type': 'multipart/form-data; boundary=' + fd.boundary,
'Authorization': 'Bearer eyJ0'
} });
console.log(JSON.parse(res.body));
//checking status code response
check(res, {'Is Success is 200' : (r) => r.status === 200})
sleep(1);
}
above code is throwing
{“type”:“about:blank”,“title”:“Unsupported Media Type”,“status”:415,“detail”:“Content-Type ‘text/plain’ is not supported.”,“instance”:“/doc/33218925310”}