Hi,
The header needs to contain the following:
"Authorization": "Bearer TokenGoesHere"
The problemIi am facing is when I set a custom header I am not able to set the proper multipart/form-data
request. Can some help with this ?
If don’t set the custom header K6 properly generates the header but header wont contain the a Authorization token so the request is getting rejected.
Thank you in advance
Can you elaborate and give an abridged example that demonstrates the problem? k6 has some issues with multipart/form-data
requests (Better handling of multipart/form-data requests · Issue #747 · grafana/k6 · GitHub), but if you use the file workaround suggested in the issue, it should work and the Authorization: Bearer ...
header shouldn’t be affected by it.
Access token is got from a third party site
Here is the code I used
const header = {
"headers": {
"Authorization": "Bearer "+accessToken,
}
}
const file = open(filePath, "b");
const tempFile = http.file(file);
const uploadData = {
file: tempFile
};
http.post("URL", uploadData);
*In this request the proper multi-part form data header is set but this will not work for use since we need the header to contain the token. Like the one set in the variable header
we need some thing like http.post(“URL”, uploadData,header ); * In the request the token is set but the other value like the boundary is not set.I want a way to auto set the value or manually set the value in header like “boundary” and all other that is required multi part form header with the token or add the token to the auto generated header by K6
@anand2seshadri
import http from "k6/http";
export default function () {
const params = {
"headers": {
"Authorization": "Bearer Something",
}
};
let uploadData = {"one": 2, "else": "some", file: http.file("file data", "file.txt")};
let res = http.post("https://httpbin.org/anything", uploadData, params);
console.log(JSON.stringify(res, null, "\t"))
}
Works as you would want … I don’t know why it isn’t working for you …
Can you make a script using httpbin.org
that shows how when you set the Authorization
header it isn’t correctly setting the form-data one ?