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

C# Net.HttpVerb类代码示例

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

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



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

示例1: GetPageAsync

        public async Task<string> GetPageAsync(string url, HttpVerb verb, string referrer = null)
        {
            var responseText = "";

            using (var request = RequestBuilder.Build(url, CommonHeaders(referrer), CookieJar))
            {
                request.Method = verb.ToVerbString();

                using (var response = await request.GetResponseAsync().ConfigureAwait(false))
                {
                    using (var stream = await response.GetResponseStreamAsync())
                    {
                        using (var sr = new StreamReader(stream))
                        {
                            responseText = sr.ReadToEnd();
                        }
                    }

                    var doc = new HtmlDocument();
                    doc.LoadHtml(responseText);

                    var scripts = doc.DocumentNode.Descendants("script");
                    foreach (var s in scripts.Where(s => s.InnerText.Contains("top.location")))
                    {
                        var newUrl = s.InnerText.Split('=')[1].Trim().Trim(new[] {' ', ';', '"'});
                        return await GetPageAsync(newUrl, verb).ConfigureAwait(false);
                    }
                }
            }

            return responseText;
        }
开发者ID:CrshOverride,项目名称:CourseraDotNet,代码行数:32,代码来源:Session.cs


示例2: RestClient

 public RestClient(string endpoint, HttpVerb method)
 {
     EndPoint = endpoint;
     Method = method;
     ContentType = "application/json";//"text/xml";
     PostData = "";
 }
开发者ID:jhamadhukar,项目名称:KryptonService,代码行数:7,代码来源:RestClient.cs


示例3: RestClient

		/**
         * RestClient with an end point, request type, post-data if any and content type
         */
        public RestClient (string endpoint, HttpVerb method, string postData,string contentTypeIdentifier)
        {
            EndPoint = endpoint;
            Method = method;
            ContentType = contentTypeIdentifier;
            PostData = postData;
        }
开发者ID:mabhi,项目名称:crossdevicepoc,代码行数:10,代码来源:RestClient.cs


示例4: RestClient

 public RestClient(string endpoint, HttpVerb method, string postData)
     : this()
 {
     EndPoint = endpoint;
     Method = method;
     PostData = postData;
 }
开发者ID:cavevs,项目名称:Clusterpoint-Client,代码行数:7,代码来源:RestClient.cs


示例5: SimpleRestClient

 public SimpleRestClient(string endpoint, HttpVerb method)
 {
     EndPoint = endpoint;
     Method = method;
     ContentType = "text/json";
     PostData = string.Empty;
 }
开发者ID:stonstad,项目名称:Signcast,代码行数:7,代码来源:SimpleRestClient.cs


示例6: RestHelper

 public RestHelper(string endpoint, HttpVerb method)
 {
     EndPoint = endpoint;
     Method = method;
     ContentType = "application/json";
     PostData = "";
 }
开发者ID:srihari-sridharan,项目名称:ActivityTracker,代码行数:7,代码来源:RESTHelper.cs


示例7: MakeRequest

        /// <summary>
        /// Make an HTTP request, with the given query args
        /// </summary>
        /// <param name="url">The URL of the request</param>
        /// <param name="httpVerb">The HTTP verb to use</param>
        /// <param name="argument">String thar represents the request data, must be in JSON format</param>
        private static string MakeRequest(Uri url, HttpVerb httpVerb, string argument = null)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = httpVerb.ToString();
            request.ContentType = "application/json";

            if (httpVerb == HttpVerb.POST)
            {
                var encoding = new ASCIIEncoding();
                var postDataBytes = new byte[0];
                if (argument != null)
                {
                    postDataBytes = encoding.GetBytes(argument);
                }

                request.ContentLength = postDataBytes.Length;

                var requestStream = request.GetRequestStream();
                requestStream.Write(postDataBytes, 0, postDataBytes.Length);
                requestStream.Close();
            }

            try
            {
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    var reader = new StreamReader(response.GetResponseStream());
                    return reader.ReadToEnd();
                }
            }
            catch (WebException e)
            {
                throw new CoticulaApiException("Server Error", e.Message);
            }
        }
开发者ID:brus07,项目名称:coticula,代码行数:41,代码来源:JsonWebClient.cs


示例8: RestClient

 public RestClient(string endpoint, HttpVerb method, Object postObj)
 {
     this.EndPoint = endpoint;
     this.Method = method;
     this.ContentType = "application/json;charset=UTF-8";
     this.PostData = Newtonsoft.Json.JsonConvert.SerializeObject(postObj);
 }
开发者ID:CapricornZ,项目名称:autobid,代码行数:7,代码来源:RestClient.cs


示例9: Build

        /// <summary>
        /// Builds a HTTP request from the given arguments.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="verb">The verb.</param>
        /// <param name="agent">The agent.</param>
        /// <param name="cookies">The cookies.</param>
        /// <param name="referer">The referer.</param>
        /// <param name="retries">The retries.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="accept">The accept.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns></returns>
        public HttpRequest Build(string url, HttpVerb verb , string agent, CookieContainer cookies = null, string referer = "", int retries = 0, int timeout = 10000, BaseMime accept = null, Encoding encoding = null)
        {
            var request = new HttpRequest
                          {
                              Url = url,
                              UserAgent = agent,
                              Verb = verb,
                              Referer = referer,
                              Retries = retries,
                              Timeout = timeout,
                              Encoding = encoding ?? Encoding.UTF8
                          };

            if (accept != null)
            {
                request.Accept = accept.ToString();
            }

            if (cookies != null)
            {
                request.Cookies = cookies;
            }

            return request;
        }
开发者ID:comsechq,项目名称:sugar,代码行数:38,代码来源:HttpService.cs


示例10: HttpClient

        public HttpClient(string endpoint, HttpVerb httpVerb, NameValueCollection headers, string contentType, string parameters)
        {
            try
            {
                this.Request = (HttpWebRequest)WebRequest.Create(endpoint);
                this.Request.ContentLength = 0;
                this.Request.ContentType = contentType.ToString();
                this.Request.Method = httpVerb.ToString();

                if (headers != null)
                {
                    foreach (var key in headers.AllKeys)
                    {
                        this.Request.Headers.Add(key, headers[key]);
                    }
                }

                if (this.Request.Method == HttpVerb.POST.ToString() && !String.IsNullOrEmpty(parameters))
                {
                    var encoding = new UTF8Encoding();
                    var bytes = Encoding.GetEncoding("utf-8").GetBytes(parameters);

                    this.Request.ContentLength = bytes.Length;

                    using (var writeStream = Request.GetRequestStream())
                    {
                        writeStream.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException(String.Format("Create WebRequest Error: {0}", ex.Message));
            }
        }
开发者ID:vgreggio,项目名称:CrossoverTest,代码行数:35,代码来源:HttpClient.cs


示例11: RestClient

 public RestClient(string endpoint, HttpVerb method, string postData)
 {
     EndPoint = endpoint;
     Method = method;
     ContentType = "application/json";
     PostData = postData;
 }
开发者ID:Dmdv,项目名称:MeltoxygenCalculator,代码行数:7,代码来源:RestClient.cs


示例12: WebRequestUtility

        public WebRequestUtility(string realm, Uri requestUri, HttpVerb verb, Boolean keepAlive, String userAgent, NetworkCredential networkCredentials)
        {
            if (requestUri == null)
                throw new ArgumentNullException("requestUri");

            this.Realm = realm;
            this.RequestUri = requestUri;
            this.Verb = verb;
            this.KeepAlive = keepAlive;
            this.UserAgent = userAgent;
            this.UseOAuth = false;
            if (networkCredentials != null)
                this.NetworkCredentials = networkCredentials;

            this.Parameters = new Dictionary<string, object>();

            if (string.IsNullOrEmpty(this.RequestUri.Query)) return;

            foreach (Match item in Regex.Matches(this.RequestUri.Query, @"(?<key>[^&?=]+)=(?<value>[^&?=]+)"))
            {
                this.Parameters.Add(item.Groups["key"].Value, item.Groups["value"].Value);
            }

            this.RequestUri = new Uri(this.RequestUri.AbsoluteUri.Replace(this.RequestUri.Query, ""));
        }
开发者ID:davidyancey,项目名称:simple-cms,代码行数:25,代码来源:WebRequestUtility.cs


示例13: RestClient

 public RestClient(string endpoint, string command, HttpVerb method)
 {
     _params = new Dictionary<string, string>();
     EndPoint = endpoint;
     Command = command;
     Method = method;
     ContentType = "text/xml";
     PostData = string.Empty;
 }
开发者ID:rpropst,项目名称:sa-demo,代码行数:9,代码来源:RestClient.cs


示例14: RestClient

 public RestClient(string endpoint, HttpVerb method, string postData, string callType, string token)
 {
     EndPoint = endpoint;
     Method = method;
     ContentType = "application/json";
     CallType = callType;
     PostData = postData;
     Token = token;
 }
开发者ID:shahdat45ict,项目名称:gocoin-.net,代码行数:9,代码来源:RestClient.cs


示例15: MakeRequest

            public void MakeRequest(HttpVerb method, string url, HeaderProvider header, AuthenticationProvider auth, BodyProvider body)
            {
                this.method = method;
                this.url = url;
                this.headers = header;
                this.auth = auth;
                this.body = body;

                this.MakeRequest();
            }
开发者ID:RainsSoft,项目名称:httplib,代码行数:10,代码来源:RequestTest.cs


示例16: GetRequestResponseElement

		public XmlElement GetRequestResponseElement(string requestPath, string data, HttpVerb verb)
		{
			IWebRequest request = _webRequestFactory.CreateWebRequest(string.Format("{0}/{1}", Url, requestPath));
			request.Method = verb;
			request.BasicAuthorization = _authorization;
			if (verb != HttpVerb.Get)
			{
				request.RequestText = data;
			}
			return request.Response.DocumentElement;
		}
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:11,代码来源:RestWebService.cs


示例17: Expecting

 public static IMockNetworkWithExpectation Expecting(
     HttpVerb verb,
     string path,
     IDictionary<string, string> queryParams,
     string requestContent)
 {
     var mock = new MockNetwork();
     mock._verb = verb;
     mock._path = path;
     mock._queryParams = queryParams;
     mock._requestContent = requestContent;
     return mock;
 }
开发者ID:GtJosh,项目名称:ds3_net_sdk,代码行数:13,代码来源:MockNetwork.cs


示例18: Open

 public void Open(HttpVerb verb, string url, bool async)
 {
 }
开发者ID:ivanjh,项目名称:scriptsharp,代码行数:3,代码来源:XmlHttpRequest.cs


示例19: HeadContentLength

 /// <summary>
         /// 发出一次新的Head请求,获取资源的长度
         /// 此请求会忽略PostingData, Files, StartPoint, EndPoint, Verb
         /// </summary>
         /// <returns>返回的资源长度</returns>
 public async Task<int> HeadContentLength()
 {
     Reset();
     HttpVerb lastVerb = verb;
     verb = HttpVerb.HEAD;
     using (HttpWebResponse res = await GetResponse())
     {
         verb = lastVerb;
         return (int)res.ContentLength;
     }
 }
开发者ID:BiaoLiu,项目名称:YLP.UWP.TOOLS,代码行数:16,代码来源:HttpRequestClient.cs


示例20: CreateRequest

        private async Task<HttpWebRequest> CreateRequest()
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            req.CookieContainer = new CookieContainer();
            //req.Headers.Add("Accept-Language", defaultLanguage);
            req.Accept = accept;
            // req.UserAgent = userAgent;
            // req.KeepAlive = false;

            //if (context.Cookies != null)
            //    req.CookieContainer.Add(context.Cookies);
            //if (!string.IsNullOrEmpty(context.Referer))
            //    req.Referer = context.Referer;

            if (verb == HttpVerb.HEAD)
            {
                req.Method = "HEAD";
                return req;
            }

            if (postingData.Count > 0 || files.Count > 0)
                verb = HttpVerb.POST;

            if (verb == HttpVerb.POST)
            {
                req.Method = "POST";

                MemoryStream memoryStream = new MemoryStream();
                StreamWriter writer = new StreamWriter(memoryStream);

                if (files.Count > 0)
                {
                    string newLine = "\r\n";
                    string boundary = Guid.NewGuid().ToString().Replace("-", "");
                    req.ContentType = "multipart/form-data; boundary=" + boundary;

                    foreach (string key in postingData.Keys)
                    {
                        writer.Write("--" + boundary + newLine);
                        writer.Write("Content-Disposition: form-data; name=\"{0}\"{1}{1}", key, newLine);
                        writer.Write(postingData[key] + newLine);
                    }

                    foreach (HttpUploadingFile file in files)
                    {
                        writer.Write("--" + boundary + newLine);
                        writer.Write(
                        "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"{2}",
                        file.FieldName,
                        file.FileName,
                        newLine
                        );
                        writer.Write("Content-Type: application/octet-stream" + newLine + newLine);
                        writer.Flush();
                        memoryStream.Write(file.Data, 0, file.Data.Length);
                        writer.Write(newLine);
                        writer.Write("--" + boundary + newLine);
                    }
                }
                else
                {
                    req.ContentType = "application/x-www-form-urlencoded";
                    StringBuilder sb = new StringBuilder();
                    foreach (string key in postingData.Keys)
                    {
                        sb.AppendFormat("{0}={1}&", key, postingData[key]);
                    }
                    if (sb.Length > 0)
                        sb.Length--;
                    writer.Write(sb.ToString());
                }

                writer.Flush();

                using (Stream stream = await req.GetRequestStreamAsync())
                {
                    memoryStream.WriteTo(stream);
                }
            }

            //if (startPoint != 0 && endPoint != 0)
            //    req.AddRange(startPoint, endPoint);
            //else if (startPoint != 0 && endPoint == 0)
            //    req.AddRange(startPoint);

            return req;
        }
开发者ID:BiaoLiu,项目名称:YLP.UWP.TOOLS,代码行数:88,代码来源:HttpRequestClient.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Net.HttpWebRequest类代码示例发布时间:2022-05-26
下一篇:
C# Net.HttpListenerResponse类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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