• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# RequestMethod类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RequestMethod的典型用法代码示例。如果您正苦于以下问题:C# RequestMethod类的具体用法?C# RequestMethod怎么用?C# RequestMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RequestMethod类属于命名空间,在下文中一共展示了RequestMethod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ExecuteUrl

        public static byte[] ExecuteUrl(string url, RequestMethod method = RequestMethod.Post, NameValueCollection Parameters = null)
        {
            using (var webClient = new WebClient())
            {
                try
                {

                    if (RequestMethod.Post == method)
                    {
                        var resBytes = webClient.UploadValues(url, Parameters);
                        return resBytes;
                    }
                    else
                    {
                        var resBytes = webClient.DownloadData(url);
                        return resBytes;
                    }

                }
                catch (Exception e)
                {

                    return null;
                }
            }
        }
开发者ID:mobsoftware,项目名称:mobsocial,代码行数:26,代码来源:HttpHelper.cs


示例2: Create

        public static RequestInfo Create(
            RequestMethod method, string target, string uriTemplate, Dictionary<string, object> parameters,
            string userAgent, Dictionary<string, string> headers, ContentType requestContentType,
            ContentType responseContentType, TimeSpan cacheDuration,
            int timeout, int retryCount,
            Uri uri, string requestBody, IRequestFactory requestFactory)
        {
            var result = new RequestInfo
                             {
                                 Target = target,
                                 UriTemplate = uriTemplate,
                                 AllowedRetries = retryCount,
                                 Uri = uri,
                                 Method = method,
                                 UserAgent = userAgent,
                                 _headers = new Dictionary<string, string>(headers ?? new Dictionary<string, string>()),
                                 RequestBody = requestBody,
                                 Parameters = new Dictionary<string, object>(parameters ?? new Dictionary<string, object>()),
                                 CacheDuration = cacheDuration,
                                 RequestContentType = requestContentType,
                                 ResponseContentType = responseContentType,
                                 Timeout = timeout
                             };

            return result;
        }
开发者ID:bitpusher,项目名称:Salient.ReliableHttpClient,代码行数:26,代码来源:RequestInfo.cs


示例3: GetResponseFromWattRequest

        private HttpWebResponse GetResponseFromWattRequest(Uri requestUrl, RequestMethod method, string postData = "")
        {
            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUrl);

                httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
                httpWebRequest.CookieContainer = _cookieJar;
                httpWebRequest.UserAgent = "CSharp HTTP Sample";
                httpWebRequest.KeepAlive = true;
                httpWebRequest.Headers.Set("Pragma", "no-cache");
                httpWebRequest.Timeout = 300000;
                httpWebRequest.Method = method.ToString();
                if (method == RequestMethod.Post)
                {
                    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    byte[] bytes = Encoding.ASCII.GetBytes(postData);
                    httpWebRequest.ContentLength = bytes.Length;
                    Stream requestStream = httpWebRequest.GetRequestStream();
                    requestStream.Write(bytes, 0, bytes.Length);
                    requestStream.Close();
                }
                return (HttpWebResponse)httpWebRequest.GetResponse();
            }
            catch
            {
                return null;
            }
        }
开发者ID:br4mbor,项目名称:WattCountdown,代码行数:29,代码来源:Watt.cs


示例4: RestMethodAttribute

 public RestMethodAttribute(string url, RequestMethod method = RequestMethod.Get, string accept = null, string contentType = null)
 {
     this.Url = url;
     this.Method = method;
     this.Accept = accept;
     this.ContentType = contentType;
 }
开发者ID:asdlvs,项目名称:SomethingRest,代码行数:7,代码来源:RestMethodAttribute.cs


示例5: PrepareRequestData

        public string PrepareRequestData(object parameters, RequestMethod method)
        {
            var result = string.Empty;

            if (parameters == null)
            {
                return result;
            }

            if (method == RequestMethod.Post)
            {
                switch (ContentType)
                {
                    case ContentType.Json:
                        return JsonConvert.SerializeObject(parameters);

                    case ContentType.Xml:
                        using (var sw = new System.IO.StringWriter())
                        {
                            var serializer = new XmlSerializer(parameters.GetType());
                            serializer.Serialize(sw, this);
                            return sw.ToString();
                        }
                }
            }

            result = ((Dictionary<string, object>)parameters).Aggregate(
                result,
                (current, parameter) => current + (parameter.Key + '=' + parameter.Value.ToString() + '&'));

            return result.Trim(new[] {'&'});
        }
开发者ID:efortunov,项目名称:patronum,代码行数:32,代码来源:RestClient.cs


示例6: CreateHttpJsonRequest

 /// <summary>
 /// Creates the HTTP json request.
 /// </summary>
 /// <param name="self">The self.</param>
 /// <param name="url">The URL.</param>
 /// <param name="method">The method.</param>
 /// <param name="metadata">The metadata.</param>
 /// <param name="credentials">The credentials.</param>
 /// <returns></returns>
 public static HttpJsonRequest CreateHttpJsonRequest(object self, Uri url, RequestMethod method, JObject metadata,
                                                     ICredentials credentials)
 {
     var request = new HttpJsonRequest(url, method, metadata, credentials);
     ConfigureRequest(self, new WebRequestEventArgs {Request = request.webRequest});
     return request;
 }
开发者ID:aduggleby,项目名称:ravendb,代码行数:16,代码来源:HttpJsonRequest.cs


示例7: Map

        public static Method Map(RequestMethod method)
        {
            Method mthd;
            Enum.TryParse(method.ToString().ToUpperInvariant(), out mthd);

            return mthd;
        }
开发者ID:SexyFishHorse,项目名称:HitboxApi4Net,代码行数:7,代码来源:RequestMethodMapper.cs


示例8: Request

 public Request()
 {
     this.contentLength = 0;
     this.contentType = MimeType.Default;
     this.cookies = new CookieCollection();
     this.hasEntityBody = false;
     this.headers = new HeaderCollection();
     this.isAuthenticated = false;
     this.isLocal = false;
     this.isSecureConnection = false;
     this.keepAlive = false;
     this.localEndPoint = null;
     this.method = RequestMethod.Unknown;
     this.protocolType = null;
     this.protocolVersion = null;
     this.rawMethod = null;
     this.rawRequest = null;
     this.rawUrl = null;
     this.referrer = null;
     this.remoteEndPoint = null;
     this.requestData = new RequestDataCollection();
     this.url = null;
     this.userAgent = null;
     this.userHostName = null;
 }
开发者ID:cathode,项目名称:Serenity,代码行数:25,代码来源:Request.cs


示例9: WebRequestWrapper

 public WebRequestWrapper(Uri uri, RequestMethod requestMethod, string contentType, ref CookieContainer cookieJar, string dataToPost = null)
 {
     this.Uri = uri;
     this.RequestMeth = requestMethod;
     this.ContentType = contentType;
     this.CookieJar = cookieJar;
     this.DataToPost = dataToPost;
 }
开发者ID:frankston,项目名称:WhatAPI,代码行数:8,代码来源:WebRequestWrapper.cs


示例10: PollServiceEventArgs

 public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId)
 {
     Request = pRequest;
     HasEvents = pHasEvents;
     GetEvents = pGetEvents;
     NoEvents = pNoEvents;
     Id = pId;
 }
开发者ID:BackupTheBerlios,项目名称:seleon,代码行数:8,代码来源:PollServiceEventArgs.cs


示例11: HtmlForm

 public HtmlForm(RequestMethod method, string action, IDictionary<string, string> errors = null)
     : base("form", null)
 {
     SetAttribut("name", "form");
     SetAttribut("method", method.ToString());
     SetAttribut("action", action);
     SetAttribut("onsubmit", "return FormIsValid()");
     _errors = errors;
 }
开发者ID:PavloRomanov,项目名称:TrainingProjects,代码行数:9,代码来源:HtmlForm.cs


示例12: BoxRequest

        public BoxRequest(RequestMethod method, Uri hostUri, string path)
        {
            Method = method;
            Host = hostUri;
            Path = path;

            HttpHeaders = new List<KeyValuePair<string, string>>();
            Parameters = new Dictionary<string, string>();
        }
开发者ID:Geekly,项目名称:box-windows-sdk-v2,代码行数:9,代码来源:BoxRequest.cs


示例13: RequestSetting

        public RequestSetting(RequestMethod method, string url)
        {
            _protocolVersion = HttpVersion.Version11;
            _method = method;
            _url = url;

            _accept = "text/html,application/xhtml+xml,*/*";
            _userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/6.0)";
        }
开发者ID:JerryXia,项目名称:ML,代码行数:9,代码来源:RequestSetting.cs


示例14: Execute

        public Stream Execute(string uri, NameValueCollection data, Dictionary<string, Stream> files, RequestMethod method = RequestMethod.POST)
        {
            String boundary = "SMSAPI-" + DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss") + (new Random()).Next(int.MinValue, int.MaxValue).ToString() + "-boundary";

            WebRequest webRequest = WebRequest.Create(baseUrl + uri);
            webRequest.Method = RequestMethodToString(method);

            if (basicAuthentication != null)
            {
                webRequest.Headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(basicAuthentication.GetUsername() + ":" + basicAuthentication.GetPassword())));
            }

            if (RequestMethod.POST.Equals(method) || RequestMethod.PUT.Equals(method))
            {
                Stream stream;

                if (files != null && files.Count > 0)
                {
                    webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
                    stream = PrepareMultipartContent(boundary, data, files);
                }
                else
                {
                    webRequest.ContentType = "application/x-www-form-urlencoded";
                    stream = PrepareContent(data);
                }

                webRequest.ContentLength = stream.Length;

                try
                {
                    stream.Position = 0;
                    CopyStream(stream, webRequest.GetRequestStream());
                    stream.Close();
                }
                catch (System.Net.WebException e)
                {
                    throw new ProxyException(e.Message, e);
                }
            }

            MemoryStream response = new MemoryStream();

            try
            {
                CopyStream(webRequest.GetResponse().GetResponseStream(), response);
            }
            catch (System.Net.WebException e)
            {
                throw new ProxyException("Failed to get response from " + webRequest.RequestUri.ToString(), e);
            }

            response.Position = 0;
            return response;
        }
开发者ID:smsapicom,项目名称:smsapicom-csharp-client,代码行数:55,代码来源:ProxyHTTP.cs


示例15: CreateContext

        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestUri"></param>
        /// <param name="method"></param>
        /// <param name="request"></param>
        protected void CreateContext(Uri requestUri, RequestMethod method, out HttpJsonRequest request)
        {
            Guard.Assert(() => requestUri != null);

            var metadata = new JObject();

            request = HttpJsonRequest.CreateHttpJsonRequest(this, new Uri(requestUri.AbsoluteUri + Guid.NewGuid()),
                                                            method, metadata, Credentials);

            ContextStorage.Add(request, SynchronizationContext.Current);
        }
开发者ID:andrewdavey,项目名称:ravendb,代码行数:17,代码来源:AsyncServerClient.cs


示例16: RequestMethodToString

 public string RequestMethodToString(RequestMethod m)
 {
     switch(m)
     {
         case RequestMethod.rmGet: return "GET";
         case RequestMethod.rmPut: return "PUT";
         case RequestMethod.rmDelete: return "DELETE";
         default:
             throw new Exception(string.Format("Request method {0} not recognized", m));
     }
 }
开发者ID:jbreiding,项目名称:JungleDiskSourceExample2,代码行数:11,代码来源:S3Request.cs


示例17: ParseRequestLine

        private bool ParseRequestLine()
        {
            string[] RequestLineDel = new string[] {" "};
            string[] splittedRequestLine = splittedRequest[0].Split(RequestLineDel, StringSplitOptions.None);

            string methodCheck = splittedRequestLine[0];
            if (methodCheck == "GET")
            {
                this.method = RequestMethod.GET;
            }

            if (methodCheck == "POST")
            {
                this.method = RequestMethod.POST;
            }


            if (methodCheck == "HEAD")
            {
                this.method = RequestMethod.HEAD;
            }


            string version = splittedRequestLine[2];
            if (version == "HTTP/1.0")
            {
                this.httpVersion = HTTPVersion.HTTP10;
            }

            else if (version == "HTTP/1.1")
            {
                this.httpVersion = HTTPVersion.HTTP11;

            }

            else 
            {
                this.httpVersion = HTTPVersion.HTTP09;
            }

            relativeURI = splittedRequestLine[1];
            bool URI = ValidateIsURI(relativeURI);
            if (URI == true)
            {
                return true;
            }
            else
            {
                return false;
            }

            
         //   throw new NotImplementedException();
        }
开发者ID:bavly,项目名称:Network-project-,代码行数:54,代码来源:Request.cs


示例18: AddEditRoute

 private void AddEditRoute(string name, RequestMethod method, string path, bool isAsync, bool isSigned, int editIndex)
 {
     if (name.Length > 0 && path.Length > 0) {
         if (editIndex == -1) {
             // Add the route
             this.routes.Add (new Route (name, method, path, isAsync, isSigned));
         } else {
             // Replace existing route
             this.routes [editIndex] = new Route (name, method, path, isAsync, isSigned);
         }
     }
 }
开发者ID:coinflipgamesllc,项目名称:sleepy,代码行数:12,代码来源:SleepyEditor.cs


示例19: GetDataV2WithJson

        /// <summary>
        ///     Method is invoked when the application needs to communicate to 
        ///     the server.
        /// </summary>
        /// <param name="method">The type of http call being sent to the server.</param>
        /// <param name="requestUrl">The command being sent to the server.</param>
        /// <param name="json">The parameters being sent to the server.</param>
        /// <returns>The response from the server as a string.</returns>

        public static async Task<string> GetDataV2WithJson(RequestMethod method, string requestUrl, string json)
        {
            //var authKeys = new Dictionary<string, string> { { "key", App.ApiKey }, { "id", BryxHelper.GetUniqueId() } };
            //var authHeader = BryxHelper.EncodeTo64(JsonConvert.SerializeObject(authKeys, Formatting.None));

            var httpClient = new HttpClient(new HttpClientHandler());
            HttpResponseMessage response;
            switch (method)
            {
                case RequestMethod.Post:
                    if (!requestUrl.Contains("authorization"))
                    {
                        httpClient.DefaultRequestHeaders.Add("X-Auth-Token", authHeader);
                    }
                    response = await httpClient.PostAsync(requestUrl, new StringContent(json));
                    if (response.IsSuccessStatusCode == false)
                    {
                        throw new HttpRequestException(((int)response.StatusCode).ToString());
                    }
                    break;
                case RequestMethod.Put:
                    httpClient.DefaultRequestHeaders.Add("X-Auth-Token", authHeader);
                    response =
                        await httpClient.PutAsync(requestUrl, new StringContent(json));
                    if (response.IsSuccessStatusCode == false)
                    {
                        throw new HttpRequestException(((int)response.StatusCode).ToString());
                    }
                    break;
                case RequestMethod.Get:
                    httpClient.DefaultRequestHeaders.Add("X-Auth-Token", authHeader);
                    response =
                        await httpClient.GetAsync(requestUrl);
                    if (response.IsSuccessStatusCode == false)
                    {
                        throw new HttpRequestException(((int)response.StatusCode).ToString());
                    }
                    break;
                case RequestMethod.Delete:
                    httpClient.DefaultRequestHeaders.Add("X-Auth-Token", authHeader);
                    var req = new HttpRequestMessage(HttpMethod.Delete, requestUrl);
                    req.Content = new StringContent(json);
                    response = await httpClient.SendAsync(req);
                    if (response.IsSuccessStatusCode == false)
                    {
                        throw new HttpRequestException(((int)response.StatusCode).ToString());
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(method), method, null);
            }
            return await response.Content.ReadAsStringAsync();
        }
开发者ID:rjb8682,项目名称:RedditClient,代码行数:62,代码来源:BryxHTTPHandler.cs


示例20: PureRequestMethod

 internal static RequestMethod PureRequestMethod(RequestMethod method)
 {
     switch (method)
     {
         case RequestMethod.ACL_GET:
             return RequestMethod.GET;
         case RequestMethod.ACL_SET:
             return RequestMethod.PUT;
         default:
             return method;
     }
 }
开发者ID:acropolium,项目名称:SharpGs,代码行数:12,代码来源:RestApiClient.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RequestOptions类代码示例发布时间:2022-05-24
下一篇:
C# RequestMessage类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap