-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receive MethodNotAllowed in v107 #1707
Comments
In my SO answer I suggested tracing the request so you can understand why you get this response. It is not RestSharp that returns the "method not allowed response", it is the server. It is only possible to find what the issue is if you can compare the actual request made by RS 107 and a working request. In my answer, I admitted that I don't see obvious issues in the code, and I suggested some improvements, but I wasn't really expecting it to work, honestly. |
MDN also suggests:
Response headers are available if you use |
Btw, I think you are trying to get the access token from an OAuth2 authorisation server. It's irrelevant for the issue, but it could be easier to deserialize the response to a proper object instead of using the dictionary. The response format is well-known:
|
The Allow Header said Get, but that is not how I did it before, it was always Post. When I try Get I get a Bad Request response. Do you have a working example for 107 with OAuth2? I am totally stuck here without being to auth first. I wish I had time at work to figure out how to use that tracer but I do not at the moment. This RestSharp update is going to require lots of changes to our automation projects and I really just need to stay on the lower version for now until I can find help. |
An example for OAuth2 would be problematic as most of the vendors use their own deviations. Unlike OAuth1, which is very strict, OAuth2 is quite relaxed in terms of what headers are used, etc. Do you have any docs of the server you are trying to call? Can you post it here? Maybe that can help. Staying on v106 for a while is a decent option. There's no immediate need for migration unless you face any of the issues fixed by v107. Still, in many cases I see people posting "working code" for v106, which is obviously wrong, but it worked because of some bugs embedded in the library and became "features"... It doesn't apply to your code, don't get me wrong please, I don't see any obvious issues there. But without much information about what the server actually wants, it's hard to diagnose the issue. |
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. |
I created a simple Twitter client with a custom authenticator. It appears that Twitter OAuth2 token endpoint works the same way as the one you're using. I had no issues with it. https://gist.github.com/alexeyzimarev/62d77bb25d7aa5bb4b9685461f8aabdd I added those tracing handlers just so I can observe the request. It didn't work the first time because I used wrong credentials. |
Thanks! I assume HttpTracer comes from the HttpTracer 2.1.1 nuget package? |
The snippet doesn't work with Cognito, I tried. I have no idea why. The only way to find out is to inspect the full request content in a working version and the not-working version. I am sorry but I spent a couple of hours yesterday on this already. The Tools namespace contains the |
Btw it is easy to compare requests using a tool like https://requestbin.com. Here, for example, is the request made with RS 107 using the authoriser I've built: To me, it looks completely legit. I am not sure what Cognito is unhappy about. |
Basically, Cognito is picky about using var client = new RestClient(options) {
Authenticator = new HttpBasicAuthenticator(_clientId, _clientSecret),
AcceptedContentTypes = new []{"application/json", "text/json", "text/x-json", "text/javascript"}
}; I am looking to improving the |
That fixed it :) |
I 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:
Expected behavior
I expected to get an auth token
Stack trace
Desktop (please complete the following information):
Additional context
Please let me know what other details I could add.
The text was updated successfully, but these errors were encountered: