Skip to content

Adding a DefaultParameter on a RestClient and use it in a Post request doesn't work #1972

Closed

Description

@giembultje

Describe the bug
Adding a DefaultParameter on a RestClient and use it in a Post request doesn't work anymore in version 108.0.2. The parameter is ignored and not send in the request. This did work in version 106.

To Reproduce
Create a restclient and when created add a default parameter:

private RestClient CurrentRestClient { get; set; } = null;

CurrentRestClient = new RestClient("myrestendpoint");
CurrentRestClient.AddDefaultParameter("f", "json");

RestRequest myrequest= new RestRequest("mypath", Method.Post);
RestResponse response = CurrentRestClient.Execute(myrequest);

Response contains a HTML output because the server did not receive the f parameter.
When adding the next line, the response is correct:

myrequest.AddParameter("f", "json");

So adding the parameter on the request works fine.

Expected behavior
When adding a default parameter as get/post, the parameter should also be sent to the server in case of a post request.

Desktop (please complete the following information):

  • OS: Windows
  • .NET version 6
  • Version 108.0.2

Activity

  1. giembultje commented on Nov 17, 2022

    @giembultje
    Author

    I've created a workaround:

    private RestResponse ExecuteWithDefaults(RestRequest request)
    {
    	foreach (Parameter parameter in CurrentRestClient.DefaultParameters)
    	{
    		request.AddParameter(parameter);
    	}
    	return CurrentRestClient.Execute(request, Method.Post);
    }           
    
  2. stale commented on Jan 7, 2023

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  3. repo-ranger commented on Jan 7, 2023

    @repo-ranger

    ⚠️ This issue has been marked wontfix and will be closed in 3 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions