restsharp/RestSharp · error · ApplicationException
Using query parameters in the base URL is not supported for
Error message
Using query parameters in the base URL is not supported for OAuth calls. Consider using AddDefaultQueryParameter instead.
What it means
Thrown by the OAuth1 authenticator when the request URL (built excluding query parameters) still contains a '?', meaning query parameters were baked into the base URL or resource string. OAuth signature base strings must separate the URL from query parameters, and the library cannot reliably split an arbitrary inline query.
Source
Thrown at src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs:244
SignatureMethod = signatureMethod,
SignatureTreatment = OAuthSignatureTreatment.Escaped,
ConsumerKey = consumerKey,
ConsumerSecret = consumerSecret,
Token = accessToken,
TokenSecret = accessTokenSecret
};
internal static void AddOAuthData(
IRestClient client,
RestRequest request,
OAuthWorkflow workflow,
OAuthType type,
string? realm
) {
var requestUrl = client.BuildUriWithoutQueryParameters(request).AbsoluteUri;
if (requestUrl.Contains('?'))
throw new ApplicationException(
"Using query parameters in the base URL is not supported for OAuth calls. Consider using AddDefaultQueryParameter instead."
);
var url = client.BuildUriString(request);
var queryStringStart = url.IndexOf('?');
if (queryStringStart != -1) url = url[..queryStringStart];
var method = request.Method.ToString().ToUpperInvariant();
var parameters = new WebPairCollection();
var query =
request.AlwaysMultipartFormData || request.Files.Count > 0
? x => BaseQuery(x) && x.Name != null && x.Name.StartsWith("oauth_")
: (Func<Parameter, bool>)BaseQuery;
parameters.AddRange(client.DefaultParameters.Where(query).ToWebParameters());
parameters.AddRange(request.Parameters.Where(query).ToWebParameters());View on GitHub (pinned to 6a50821692)
Solutions
- Move query parameters out of BaseUrl/Resource and add them via request.AddQueryParameter or client.AddDefaultQueryParameter.
- Set BaseUrl to the bare path with no query string.
- If a query is genuinely needed, use AddDefaultQueryParameter as the error message suggests.
Example fix
// before
var client = new RestClient("https://api.host/resource?api_key=secret");
// after
var client = new RestClient("https://api.host/resource");
client.AddDefaultQueryParameter("api_key", "secret"); Defensive patterns
Strategy: validation
Validate before calling
if (client.Options.BaseUrl?.ToString().Contains('?') == true || request.Resource.Contains('?')) throw new InvalidOperationException("Remove inline query params from BaseUrl/Resource"); Try / catch
try { await client.ExecuteAsync(request); } catch (ApplicationException ex) when (ex.Message.Contains("query parameters in the base URL")) { /* move query params to AddQueryParameter and retry */ } Prevention
- Never embed query strings in RestClientOptions.BaseUrl.
- Add query parameters via AddQueryParameter / AddDefaultQueryParameter only.
- Sanitize copied URLs to strip query strings before using as BaseUrl.
When it happens
Trigger: Configuring RestClientOptions.BaseUrl (or RestRequest.Resource) with a URL that includes a query string such as 'https://host/path?x=1', then using an OAuth1Authenticator. AddOAuthData builds the URL without query params and detects the leftover '?'.
Common situations: Pasting a full URL with query params into BaseUrl; embedding API keys or session tokens as inline query in the base URL; reusing a captured browser URL verbatim as the resource.
Related errors
- Only HMAC-SHA1, HMAC-SHA256, and RSA-SHA1 are currently supp
- Token request failed with status {response.StatusCode}: {bod
- Token endpoint returned an invalid response: {body}
- Request resource doesn't contain a valid scheme for an empty
AI-assisted analysis of restsharp/RestSharp@6a50821692 (2026-08-13).
Data as JSON: /api/errors/db67155f721927d7.
Report an issue: GitHub.