Receive MethodNotAllowed in v107
See original GitHub issueI am attempting a POST request in v107 that used to work before v107. See https://stackoverflow.com/questions/70686539/v107-getting-status-code-of-methodnotallowed-on-a-post-request-that-used-to-work for details. As suggested by Alexey there I have re-written some code and now I get an exception with MethodNotAllowed, rather than a response with status - MethodNotAllowed.
To Reproduce Reworked Code:
//constructor
public MerlinServiceBase()
{
GetCreds();
_authClient = new RestClient(_authUrl);
_authClient.Authenticator = new HttpBasicAuthenticator(_authClientId, _authClientSecret);
}
private async System.Threading.Tasks.Task<string> GetAuthTokenAsync()
{
var request = new RestRequest().AddParameter("grant_type", "client_credentials");
var response = await _authClient.PostAsync<Dictionary<string, string>>(request);
return response["access_token"];
}
Expected behavior I expected to get an auth token
Stack trace
System.Net.Http.HttpRequestException
HResult=0x80131500
Message=Request failed with status code MethodNotAllowed
Source=RestSharp
StackTrace:
at RestSharp.RestClientExtensions.<PostAsync>d__11`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at RentalWebClient.V3.QA.Automation.UI.MerlinServiceBase.<GetAuthTokenAsync>d__10.MoveNext() in C:\Source\OpenTech\Kiosk\Ota.Kiosk.RentalWebClient.V3.QA.Automation\RentalWebClient.V3.QA.Automation.UI\_Merlin API\Merlin_ServiceBase.cs:line 87
This exception was originally thrown at this call stack:
[External Code]
RentalWebClient.V3.QA.Automation.UI.MerlinServiceBase.GetAuthTokenAsync() in Merlin_ServiceBase.cs
Desktop (please complete the following information):
- OS: Windows 10
- .NET Framework 4.7.2
Additional context Please let me know what other details I could add.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
v107 Getting Status Code of MethodNotAllowed on a Post ...
I am trying to get an auth token using RestSharp v107 and I cannot figure out how to make it work. I have...
Read more >How to Fix the HTTP 405 Method Not Allowed Error
It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the...
Read more >method not allowed - Microsoft Q&A
while working with identity server . i used restsharp .its giving me an error "method not allowed" as a response, can any body...
Read more >Error handling
It means that there's no RestResponse to set the response status to error. We decided to throw an exception when such a request...
Read more >How to Fix HTTP Error 405 Method Not Allowed
When a website displays the 405 Method Not Allowed notification, it indicates a Hypertext Transfer Protocol (HTTP) error.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We use Amazon Cognito with client_credentials: https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html
I am still trying stuff here and there, learning about and finding my way around the the new and old layouts of the client and response objects. A minor thing I noticed is that Resource is set to “” instead of null on the new RestRequest object, but moving “/token” to there from my base url seemed to not help (or hurt) at all.
That fixed it 😃 Thank you so much for spending so much of your valuable time on it, it is appreciated!