How to set header when sending delete request?

Such a case:
I read user token from a json file , then set header like this
image
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.

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.

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.

Really appreciate it.
I tried this way, still got 401.

Please post what your new code is, so we can try to help you

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?
image

Resolved.
Thanks a lot.@ned @Brenda

1 Like