jessie
September 13, 2022, 7:09am
1
Such a case:
I read user token from a json file , then set header like this
Then send request like this
It can work for all request excepts delete, console info shows that token hasn’t been set when sending delete request?
How can I set token in header for delete request? Please give me some suggestion.
Brenda
September 13, 2022, 7:30am
3
Maybe you can add param to url, please refer to below picture.
Hope it can help you.
You shouldn’t use http[method]
, since not all k6/http
methods have the same signature. For example, http.get()
and http.head()
don’t accept a body
, and the DELETE
method is actually called http.del()
.
What you should use instead is the generic http.request()
function , which accepts the method
as its first argument.
jessie
September 13, 2022, 8:14am
6
Thanks for your reply, suppose that members in my team only use get/post/put/del here, and I have a parameter 'hasPayload ’ to control whether accept a body or not.Just like the picture bellow:
Then , if I use generic http.request() function instead,
How can I set token in header this way?
Yes, look at the documentation , http.request()
can do everything the other k6/http
helper methods can do.
jessie
September 13, 2022, 8:32am
8
Really appreciate it.
I tried this way, still got 401.
Please post what your new code is, so we can try to help you
jessie
September 13, 2022, 8:47am
10
Hi, Ned, really thanks for your reply again.
However, I change my code to http.request() like bellow,
still get 403. It sames that token set in header still not work . Could you please help me out?
jessie
September 13, 2022, 8:53am
11
Resolved.
Thanks a lot.@ned @Brenda
1 Like