HTTP Post returns a "MethodNotAllowed" error code

Im trying to create a simple HTTP client with the following code.

Uri uri = new Uri(url);
var postData = new StringContent("Will Echo!", Encoding.UTF8);
try {
                var statusCode = await client.PostAsync(uri, postData);
                if (statusCode.IsSuccessStatusCode) {
                    var definitionResponse = await statusCode.Content.ReadAsStringAsync();
            return true;
                }
                else {
                    Debug.WriteLine("Error Code: " + statusCode.StatusCode);
                    return false;
                }
            }
            catch (Exception e) {
                Debug.WriteLine("Exception thrown: " + e);
                return false;
       }

This code will always print "Error Code: MethodNotAllowed". However this code will work with statusCode = await client.GetAsync(uri);

So what is causing this error? Is it because the url is not a secured http? Am I using the wrong port? Am I passing the wrong kind of Data?
Any help would be appreciated.

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Could you post the detailed error information. Or you can add breakpoints to debug to find which line codes that caused the problem.

Sign In or Register to comment.