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


C# RequestMethod类代码示例

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


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


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