Restsharp: Removing Rest Request Headers

Created on 24 May 2017  ·  6Comments  ·  Source: restsharp/RestSharp

Is there a way by which I can remove the header value from RestSharp request.
Ex. I have added token in the request header and after request execution realized that, token is expired. I wanted to apply regenerated to token to request. If I simply add it using AddHeader, it creates a new parameter entry with same name, and does not override the earlier one.

Looking for a way where either i can remove and add or update header.

If this is not supported,
1) one can enumerate the parameters and find a parameter by parameter type and name
2) once found, remove it from Parameters list (using List.Remove)
3) Then, add it again

I can generate PR by exposing the method. Please suggest if this is good to have feature in the library.

Thanks
Nilesh

Most helpful comment

You can submit a PR with AddOrUpdateHeader like it was done for parameters: https://github.com/restsharp/RestSharp/blob/5d0286598bb0523524e9a6de684633d2b6356dea/RestSharp/RestRequest.cs#L461

But don't forget method xml documentation.

All 6 comments

request.Parameters.remove()

You can submit a PR with AddOrUpdateHeader like it was done for parameters: https://github.com/restsharp/RestSharp/blob/5d0286598bb0523524e9a6de684633d2b6356dea/RestSharp/RestRequest.cs#L461

But don't forget method xml documentation.

Any luck submitting a PR for this?

Im having the same issue as the OP, seems this was never done, i second the notion.
Otherwise, i think it would help those unfamiliar get it done.

For client instance, just: client.RemoveDefaultParameter("Authorization");

I think it is already fixed. We only add default parameters if there is no parameter with the same name available in the list of request parameters. It can be overridden by AllowMultipleDefaultParametersWithSameName, which is false by default.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomasd3 picture thomasd3  ·  5Comments

tomgallard picture tomgallard  ·  6Comments

DuBistKomisch picture DuBistKomisch  ·  6Comments

wojciechrak picture wojciechrak  ·  3Comments

ghd258 picture ghd258  ·  6Comments