Test Supported HTTP Methods

674 views Asked by At

I'm trying to test supported methods in HTTP, essentially I'm creating httpwebrequest with verb to see if It's supported, how can I achieve this, how can I achieve that? Below is my code attempt.

My code is so far as the following

public enum enumHttpVerbs
    {
        DELETE,
        GET,
        HEAD,
        OPTIONS,
        PATCH,
        POST,
        PUT,
        TRACE
    }

public bool IsSupportedVerb(Uri url, enumHttpVerbs verb)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    switch (verb)
    {
        case enumHttpVerbs.DELETE:
            request.Method = "DELETE";
            break;
        case enumHttpVerbs.GET:
            request.Method = "GET";
            break;
        case enumHttpVerbs.HEAD:
            request.Method = "HEAD";
            break;
        case enumHttpVerbs.OPTIONS:
            request.Method = "OPTIONS";
            break;
        case enumHttpVerbs.PATCH:
            request.Method = "PATCH";
            break;
        case enumHttpVerbs.POST:
            request.Method = "POST";
            break;
        case enumHttpVerbs.PUT:
            request.Method = "PUT";
            break;
        default:
            break;
    }
    try
    {
        request.GetResponse();
        return true;
    }
    catch(Exception ex) {

    }
    return false;
}
0

There are 0 answers