当前位置: 首页>>代码示例>>C#>>正文


C# HttpVerbs.ToString方法代码示例

本文整理汇总了C#中HttpVerbs.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpVerbs.ToString方法的具体用法?C# HttpVerbs.ToString怎么用?C# HttpVerbs.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpVerbs的用法示例。


在下文中一共展示了HttpVerbs.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteRequest

        private async Task<HttpResponseMessage> ExecuteRequest(HttpVerbs method, Uri requestUri, HttpContent content = null)
        {
            var request = WebRequest.CreateHttp(requestUri);
            var httpResponseMessage = new HttpResponseMessage();

            request.Headers = DefaultRequestHeaders;
            request.Method = method.ToString();
            request.Accept = "*/*";

            httpResponseMessage.Request = request;

            Logger.LogWebRequest(request);
            if (content != null) Logger.LogVerbose(content.ToString());

            try
            {
                if (method == HttpVerbs.POST)
                {
                    request.ContentType = content.ContentType;

                    var requestStreamTask = Task<Stream>.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null);
                    using (Stream stream = await requestStreamTask.ConfigureAwait(false))
                    {
                        content.WriteToStream(stream);
                    }
                }

                var responseTask = Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null);
                using (var response = await responseTask.ConfigureAwait(false) as HttpWebResponse)
                {
                    httpResponseMessage.SetResponseData(response);
                    Logger.LogWebResponse(response);
                }
            }
            catch (WebException we)
            {
                var response = (HttpWebResponse)we.Response;
                if (response != null)
                    httpResponseMessage.SetResponseData(response);

                Logger.Log(we);
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }

            return httpResponseMessage;
        }
开发者ID:Bougyz,项目名称:Build2013RealWorldStocks,代码行数:49,代码来源:HttpClient.cs

示例2: IsHttpMethod

 // CODEREVIEW: this implementation kind of misses the point of HttpVerbs
 // by falling back to string comparison, consider something better
 // also, how do we keep this switch in sync?
 public static bool IsHttpMethod(this HttpRequestBase request, HttpVerbs httpMethod, bool allowOverride) {
     switch (httpMethod) {
         case HttpVerbs.Get:
             return request.IsHttpMethod("GET", allowOverride);
         case HttpVerbs.Post:
             return request.IsHttpMethod("POST", allowOverride);
         case HttpVerbs.Put:
             return request.IsHttpMethod("PUT", allowOverride);
         case HttpVerbs.Delete:
             return request.IsHttpMethod("DELETE", allowOverride);
         case HttpVerbs.Head:
             return request.IsHttpMethod("HEAD", allowOverride);
         default:
             // CODEREVIEW: does this look reasonable?
             return request.IsHttpMethod(httpMethod.ToString().ToUpperInvariant(), allowOverride);
     }
 }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:20,代码来源:HttpRequestBaseExtensions.cs

示例3: IsUniquePropertyValidator

        //"{PropertyName} must be unique."
        public IsUniquePropertyValidator(IPropertyValidatorService service, string errorMessage,
                         string action,
                         string controller,
                         HttpVerbs HttpVerb = HttpVerbs.Get,
                         string additionalFields = "")
            : base(errorMessage)
        {
            this._service = service;
            var httpContext = HttpContext.Current;

            if (httpContext != null)
            {
                var httpContextBase = new HttpContextWrapper(httpContext);
                var routeData       = new RouteData();
                var requestContext  = new RequestContext(httpContextBase, routeData);

                var helper       = new UrlHelper(requestContext);
                Url              = helper.Action(action, controller);
                HttpMethod       = HttpVerb.ToString();
                AdditionalFields = additionalFields;
            }
        }
开发者ID:netsouls,项目名称:eCentral,代码行数:23,代码来源:IsUniquePropertyValidator.cs

示例4: RemoteValidator

        public RemoteValidator(string errorMessage, string action, string controller, HttpVerbs httpVerb = HttpVerbs.Get, string additionalFields = "")
            : base(errorMessage)
        {
            var httpContext = HttpContext.Current;

            if (httpContext == null)
            {
                var request = new HttpRequest("/", "http://ubasolutions.com", "");
                var response = new HttpResponse(new StringWriter());
                httpContext = new HttpContext(request, response);
            }

            var httpContextBase = new HttpContextWrapper(httpContext);
            var routeData = new RouteData();
            var requestContext = new RequestContext(httpContextBase, routeData);

            var helper = new UrlHelper(requestContext);

            Url = helper.Action(action, controller);
            HttpMethod = httpVerb.ToString();
            AdditionalFields = additionalFields;
        }
开发者ID:pjmagee,项目名称:CI3540,代码行数:22,代码来源:RemoteValidator.cs

示例5: DoDataRequest

        public Stream DoDataRequest(string query, HttpVerbs method, Action<Stream> data, string contenttype)
        {
            HttpWebRequest req = WebRequest.Create(new Uri(Url,query)) as HttpWebRequest;

            if (Credentials != null)
                req.Credentials = Credentials;

            req.Method = method.ToString();

            //req.Timeout = System.Threading.Timeout.Infinite;
            if (!string.IsNullOrEmpty(contenttype))
                req.ContentType = contenttype;

            if (data != null)
            {
                using (Stream ps = req.GetRequestStream())
                {
                    data.Invoke(ps);
                }
            }
            try
            {
                HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

                if (resp.StatusCode == HttpStatusCode.OK || resp.StatusCode == HttpStatusCode.Created)
                    return resp.GetResponseStream();

                throw new RestException(resp.StatusCode, resp.StatusDescription);
            }
            catch (WebException ex)
            {
                HttpWebResponse resp = ex.Response as HttpWebResponse;
                StreamReader sr = new StreamReader(resp.GetResponseStream());
                string contents = sr.ReadToEnd();
                throw new RestException(resp.StatusCode, resp.StatusDescription);
            }


        }
开发者ID:tocsoft,项目名称:Common.Helpers,代码行数:39,代码来源:RestClient.cs

示例6: ProcessRequest

        public RequestResult ProcessRequest(string url, HttpVerbs httpVerb, NameValueCollection formValues, NameValueCollection headers)
        {
            if (url == null) throw new ArgumentNullException("url");

            // Fix up URLs that incorrectly start with / or ~/
            if (url.StartsWith("~/"))
                url = url.Substring(2);
            else if(url.StartsWith("/"))
                url = url.Substring(1);

            // Parse out the querystring if provided
            string query = "";
            int querySeparatorIndex = url.IndexOf("?");
            if (querySeparatorIndex >= 0) {
                query = url.Substring(querySeparatorIndex + 1);
                url = url.Substring(0, querySeparatorIndex);
            }                

            // Perform the request
            LastRequestData.Reset();
            var output = new StringWriter();
            string httpVerbName = httpVerb.ToString().ToLower();
            var workerRequest = new SimulatedWorkerRequest(url, query, output, Cookies, httpVerbName, formValues, headers);
            HttpRuntime.ProcessRequest(workerRequest);

            // Capture the output
            AddAnyNewCookiesToCookieCollection();
            Session = LastRequestData.HttpSessionState;
            return new RequestResult
            {
                ResponseText = output.ToString(),
                ActionExecutedContext = LastRequestData.ActionExecutedContext,
                ResultExecutedContext = LastRequestData.ResultExecutedContext,
                Response = LastRequestData.Response,
            };
        }
开发者ID:authorunknown,项目名称:SpecFlow-Examples,代码行数:36,代码来源:BrowsingSession.cs

示例7: HTTP

        /// <summary>
        /// Performs an HTTP request to an URL using the specified method and data, returning the response as a string
        /// </summary>
        protected virtual LatchResponse HTTP(Uri URL, HttpVerbs method, IDictionary<string, string> headers, IDictionary<string, string> data)
        {
            HttpWebRequest request = BuildHttpUrlConnection(URL, headers);
            if (request == null)
            {
                throw new HttpException("Request could not be created correctly");
            }
            request.Method = method.ToString();

            try
            {
                if (method.Equals(HttpVerbs.Post) || method.Equals(HttpVerbs.Put))
                {
                    request.ContentType = HTTP_HEADER_CONTENT_TYPE_FORM_URLENCODED;
                    using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
                    {
                        sw.Write(GetSerializedParams(data));
                        sw.Flush();
                    }
                }

                using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    string json = sr.ReadToEnd();
                    return new LatchResponse(json);
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:iserranos,项目名称:latch-sdk-dotnet,代码行数:35,代码来源:LatchAuth.cs

示例8: StringToSign

        private IDictionary<string, string> StringToSign(HttpVerbs httpMethod, string queryString, IDictionary<string, string> xHeaders, string UTC, IDictionary<string, string> param)
        {
            string stringToSign = String.Concat(httpMethod.ToString().ToUpper(), "\n", UTC, "\n", GetSerializedHeaders(xHeaders), "\n", queryString.Trim());
            {
                string serializedParams = GetSerializedParams(param);
                if (!String.IsNullOrEmpty(serializedParams))
                {
                    stringToSign = String.Concat(stringToSign, "\n", serializedParams);
                }
            }
            string signedData = String.Empty;
            try
            {
                signedData = SignData(stringToSign.ToString());
            }
            catch (Exception e)
            {
                return null;
            }

            string authorizationHeader = String.Concat(AUTHORIZATION_METHOD, AUTHORIZATION_HEADER_FIELD_SEPARATOR, this.appId, AUTHORIZATION_HEADER_FIELD_SEPARATOR, signedData);

            IDictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add(AUTHORIZATION_HEADER_NAME, authorizationHeader);
            headers.Add(DATE_HEADER_NAME, UTC);
            return headers;
        }
开发者ID:iserranos,项目名称:latch-sdk-dotnet,代码行数:27,代码来源:LatchAuth.cs

示例9: ProcessRequest

        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="httpVerb">The HTTP verb.</param>
        /// <param name="formValues">The form values.</param>
        /// <param name="headers">The headers.</param>
        /// <returns>The request of executing the simulate request.</returns>
        private RequestResult ProcessRequest(
            string url, HttpVerbs httpVerb, NameValueCollection formValues, NameValueCollection headers)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            // TODO: Doesn't the BCL contain methods to do all this URL handling already?

            // Fix up URLs that incorrectly start with / or ~/
            // TODO: Why is this incorrect? They can be handled fine and make the library easier to use by avoiding unecessary restrictions.
            if (url.StartsWith("~/", true, CultureInfo.InvariantCulture))
            {
                url = url.Substring(2);
            }
            else if (url.StartsWith("/", true, CultureInfo.InvariantCulture))
            {
                url = url.Substring(1);
            }

            // Parse out the querystring if provided
            var query = string.Empty;
            var querySeparatorIndex = url.IndexOf("?");

            if (querySeparatorIndex >= 0)
            {
                query = url.Substring(querySeparatorIndex + 1);
                url = url.Substring(0, querySeparatorIndex);
            }

            // Perform the request
            LastRequestData.Reset();
            var output = new StringWriter();
            var httpVerbName = httpVerb.ToString().ToLower();
            var workerRequest = new SimulatedWorkerRequest(
                url, query, output, this.Cookies, httpVerbName, formValues, headers);
            HttpRuntime.ProcessRequest(workerRequest);

            // Capture the output
            this.AddAnyNewCookiesToCookieCollection();
            this.Session = LastRequestData.HttpSessionState;
            return new RequestResult
                {
                    ResponseText = output.ToString(),
                    ActionExecutedContext = LastRequestData.ActionExecutedContext,
                    ResultExecutedContext = LastRequestData.ResultExecutedContext,
                    Response = LastRequestData.Response,
                };
        }
开发者ID:abrkn,项目名称:MvcIntegrationTestFramework,代码行数:58,代码来源:BrowsingSession.cs

示例10: RouteAttribute

 /// <summary>
 /// Specify the route information for an action.
 /// </summary>
 /// <param name="routeUrl">The url that is associated with this action</param>
 /// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
 public RouteAttribute(string routeUrl, HttpVerbs allowedMethods)
     : this(routeUrl, allowedMethods.ToString().ToUpper().SplitAndTrim(new[] { "," }))
 {
 }
开发者ID:robby,项目名称:AttributeRouting,代码行数:9,代码来源:RouteAttribute.cs


注:本文中的HttpVerbs.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。