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


C# WebHeaderCollection.Add方法代码示例

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


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

示例1: VerifyAddHeaderIsIllegal

        private bool VerifyAddHeaderIsIllegal(WebHeaderCollection wrc, string header, string content, Type exceptionType)
        {
            bool res = true;

            try
            {
                Log.Comment("Set Headers Properties for header: '" + header + "', with value: '" + content + "'");

                if (null == content)
                    wrc.Add(header);
                else
                    wrc.Add(header, content);

                Log.Comment("Illegal header was set:  Failed.");
                res = false;
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, exceptionType))
                {
                    res = false;
                }
            }

            return res;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:26,代码来源:WebHeaderCollectionTests.cs

示例2: GetContent

        private AmazonProduct GetContent(String ASin)
        {
            var content = "";

            var client = new WebClient();

            var headers = new WebHeaderCollection();

            headers.Add(HttpRequestHeader.Accept, "text/html, application/xhtml+xml, */*");
            //headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB");
            headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

            client.Headers = headers;

            var rawhtml = client.DownloadString("http://www.amazon.co.uk/dp/"+ ASin);

            HtmlAgilityPack.HtmlDocument Html = new HtmlAgilityPack.HtmlDocument();

            Html.LoadHtml(rawhtml);

            var title = GetTitle(Html);

            var description = GetDescription(Html);

            AmazonProduct prod = new AmazonProduct() { Description = description, Title = title };

            return prod;
        }
开发者ID:Neil19533,项目名称:AParser,代码行数:29,代码来源:AZonController.cs

示例3: DigestAuthenticationSchemeAdded

		public void DigestAuthenticationSchemeAdded()
		{
			WebHeaderCollection headers = new WebHeaderCollection();
			headers.Add(HttpResponseHeader.WwwAuthenticate, "Digest realm='test'");
			headers.Add(HttpResponseHeader.WwwAuthenticate, "NTLM");
			HttpAuthenticationHeader authenticationHeader = new HttpAuthenticationHeader(headers);

			Assert.AreEqual("Digest,NTLM", authenticationHeader.AuthenticationType);
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:9,代码来源:HttpAuthenticationHeaderTests.cs

示例4: IsWindowsAuthentication

		public void IsWindowsAuthentication()
		{
			WebHeaderCollection headers = new WebHeaderCollection();
			headers.Add(HttpResponseHeader.WwwAuthenticate, "Negotiate");
			headers.Add(HttpResponseHeader.WwwAuthenticate, "NTLM");
			HttpAuthenticationHeader authenticationHeader = new HttpAuthenticationHeader(headers);

			Assert.AreEqual("Negotiate,NTLM", authenticationHeader.AuthenticationType);
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:9,代码来源:HttpAuthenticationHeaderTests.cs

示例5: GetHttpHeaders

 protected static WebHeaderCollection GetHttpHeaders(BaseRequest request, Options options)
 {
     string randomString = DateTime.Now.ToString("ddMMyyyyhhmmssffff");
     WebHeaderCollection headers = new WebHeaderCollection();
     headers.Add("Accept", "application/json");
     headers.Add(RANDOM_HEADER_NAME, randomString);
     headers.Add(CLIENT_VERSION, "iyzipay-dotnet-2.1.9");
     headers.Add(AUTHORIZATION, PrepareAuthorizationString(request, randomString, options));
     return headers;
 }
开发者ID:iyzico,项目名称:iyzipay-dotnet,代码行数:10,代码来源:IyzipayResource.cs

示例6: ManyAuthenticationSchemesAdded

		public void ManyAuthenticationSchemesAdded()
		{
			WebHeaderCollection headers = new WebHeaderCollection();
			headers.Add(HttpResponseHeader.WwwAuthenticate, "Negotiate");
			headers.Add(HttpResponseHeader.WwwAuthenticate, "NTLM");
			headers.Add(HttpResponseHeader.WwwAuthenticate, "Basic realm='test'");
			HttpAuthenticationHeader authenticationHeader = new HttpAuthenticationHeader(headers);

			Assert.AreEqual("Negotiate,NTLM,Basic", authenticationHeader.AuthenticationType);
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:10,代码来源:HttpAuthenticationHeaderTests.cs

示例7: RestRequest

 public RestRequest()
 {
     Headers = new WebHeaderCollection();
     Headers.Add(HttpRequestHeader.CacheControl, "no-store, must-revalidate");
     Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip");
     Encoding = Encoding.UTF8;
     Resource = string.Empty;
     Timeout = 2000;
     Data = string.Empty;
     ContentType = ContentType.TextPlain;
     Method = HttpMethod.GET;
 }
开发者ID:cannero,项目名称:restlib,代码行数:12,代码来源:RestRequest.cs

示例8: PreparePackets

        private void PreparePackets(long length)
        {
            //string postData = "?" + string.Join("&", arguments.Select(x => x.Key + "=" + x.Value).ToArray());
            postMethod = Encoding.Default.GetBytes(string.Format("POST {0} HTTP/1.1\r\n", url.AbsolutePath));

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add(HttpRequestHeader.ContentType, "multipart/form-data; boundary=" + boundary);
            headers.Add(HttpRequestHeader.Host, url.DnsSafeHost);
            headers.Add(HttpRequestHeader.ContentLength, (request.Length + length + requestEnd.Length).ToString());
            headers.Add(HttpRequestHeader.Connection, "Keep-Alive");
            headers.Add(HttpRequestHeader.CacheControl, "no-cache");

            headerBytes = headers.ToByteArray();
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:14,代码来源:TCPClient.cs

示例9: Create

        public static WebResponse Create(HttpStatusCode statusCode,
            IDictionary<string,string> headers, string body = null)
        {
            var type = typeof(HttpWebResponse);
            var assembly = Assembly.GetAssembly(type);
            var obj = assembly.CreateInstance("System.Net.HttpWebResponse");

            var webHeaders = new WebHeaderCollection();
            foreach (var header in headers)
            {
                webHeaders.Add(header.Key,header.Value);
            }

            Stream responseBodyStream = null;
            body = body ?? string.Empty;
            responseBodyStream = Utils.CreateStreamFromString(body);

            var statusFieldInfo = type.GetField("m_StatusCode",
                BindingFlags.NonPublic | BindingFlags.Instance);
            var headersFieldInfo = type.GetField("m_HttpResponseHeaders",
                BindingFlags.NonPublic | BindingFlags.Instance);
            var streamFieldInfo = type.GetField("m_ConnectStream",
                BindingFlags.NonPublic | BindingFlags.Instance);
            var contentLengthFieldInfo = type.GetField("m_ContentLength",
                BindingFlags.NonPublic | BindingFlags.Instance);

            statusFieldInfo.SetValue(obj, statusCode);
            headersFieldInfo.SetValue(obj, webHeaders);
            streamFieldInfo.SetValue(obj, responseBodyStream);
            contentLengthFieldInfo.SetValue(obj, responseBodyStream.Length);

            return obj as HttpWebResponse;
        }
开发者ID:wmatveyenko,项目名称:aws-sdk-net,代码行数:33,代码来源:MockWebResponse.cs

示例10: ReadPageWithHeaders

 public static string ReadPageWithHeaders(string url, NameValueCollection headers, NameValueCollection outputHeaders)
 {
     WebRequest myWebRequest = WebRequest.Create(url);
     if (headers.Count > 0)
     {
         WebHeaderCollection webHeaders;
         webHeaders = new WebHeaderCollection();
         foreach (string key in headers.Keys)
         {
             webHeaders.Add(key, headers[key]);
         }
         myWebRequest.Headers = webHeaders;
     }
     WebResponse myWebResponse = myWebRequest.GetResponse();
     Stream ReceiveStream = myWebResponse.GetResponseStream();
     Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
     StreamReader readStream = new StreamReader(ReceiveStream, encode);
     string strResponse = readStream.ReadToEnd();
     readStream.Close();
     if (outputHeaders != null)
     {
         foreach (string key in myWebResponse.Headers.Keys)
         {
             outputHeaders.Add(key, myWebResponse.Headers[key]);
         }
     }
     myWebResponse.Close();
     return strResponse;
 }
开发者ID:spiffydudex,项目名称:navbot,代码行数:29,代码来源:WebUtils.cs

示例11: GetHttpWebResponse

        public static TestableHttpWebResponse GetHttpWebResponse(HttpResponseSettings httpResponseSettings, Uri uri, string expectedContentType)
        {
            SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new System.Runtime.Serialization.FormatterConverter());
            StreamingContext sc = new StreamingContext();
            WebHeaderCollection headers = new WebHeaderCollection();

            foreach (var kvp in httpResponseSettings.HeaderValues)
                headers.Add(kvp.Key, kvp.Value);

            si.AddValue("m_HttpResponseHeaders", headers);
            si.AddValue("m_Uri", uri);
            si.AddValue("m_Certificate", null);
            si.AddValue("m_Version", HttpVersion.Version11);
            si.AddValue("m_StatusCode", httpResponseSettings.StatusCode);
            si.AddValue("m_ContentLength", 0);
            si.AddValue("m_Verb", "GET");
            si.AddValue("m_StatusDescription", httpResponseSettings.StatusDescription);
            si.AddValue("m_MediaType", expectedContentType);

            var webResponse = new TestableHttpWebResponse(si, sc, httpResponseSettings.ResponseStream);
 
            if (httpResponseSettings.ExpectException)
                throw new WebException("This request failed", new Exception(httpResponseSettings.StatusDescription), WebExceptionStatus.ProtocolError, webResponse);
            else
                return webResponse;
        }
开发者ID:renlesterdg,项目名称:BasicAzureStorageSDK,代码行数:26,代码来源:TestableHttpWebResponse.cs

示例12: GetAccessToken

        public bool GetAccessToken(string code)
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("client_id", this.oAuthInfos.Client_ID);
            args.Add("client_secret", this.oAuthInfos.Client_Secret);
            args.Add("code", code);

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add("Accept", "application/json");

            string response = this.SendPostRequest(this.GistCompleteUri.ToString(), args, headers: headers);

            if (!string.IsNullOrEmpty(response))
            {
                OAuth2Token token = JsonConvert.DeserializeObject<OAuth2Token>(response);

                if (token != null && !string.IsNullOrEmpty(token.access_token))
                {
                    this.oAuthInfos.Token = token;
                    return true;
                }
            }

            return false;
        }
开发者ID:Gsaico,项目名称:ScreenShot,代码行数:25,代码来源:Gist.cs

示例13: GetAccessToken

        public bool GetAccessToken(string code)
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("client_id", AuthInfo.Client_ID);
            args.Add("client_secret", AuthInfo.Client_Secret);
            args.Add("code", code);

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add("Accept", "application/json");

            string response = SendPostRequest("https://github.com/login/oauth/access_token", args, headers: headers);

            if (!string.IsNullOrEmpty(response))
            {
                OAuth2Token token = JsonConvert.DeserializeObject<OAuth2Token>(response);

                if (token != null && !string.IsNullOrEmpty(token.access_token))
                {
                    AuthInfo.Token = token;
                    return true;
                }
            }

            return false;
        }
开发者ID:yoykiee,项目名称:ShareX,代码行数:25,代码来源:Gist.cs

示例14: Test_WebHeader_01

 public static void Test_WebHeader_01()
 {
     WebHeaderCollection headers = new WebHeaderCollection();
     headers.Add("xxx", "yyy");
     headers.Add("xxx", "yyy222");
     headers.Add("zzz", "fff");
     headers.Add("xxx", "ttt");
     for (int i = 0; i < headers.Count; ++i)
     {
         string key = headers.GetKey(i);
         foreach (string value in headers.GetValues(i))
         {
             Trace.WriteLine("{0}: {1}", key, value);
         }
     }
 }
开发者ID:labeuze,项目名称:source,代码行数:16,代码来源:Test_HttpLog.cs

示例15: SendBuildInfo

        public void SendBuildInfo(String buildInfoJson)
        {
            string url = _artifactoryUrl + BUILD_REST_URL;

            try
            {
                var bytes = Encoding.Default.GetBytes(buildInfoJson);
                {
                    //Custom headers
                    WebHeaderCollection headers = new WebHeaderCollection();
                    headers.Add(HttpRequestHeader.ContentType, "application/vnd.org.jfrog.build.BuildInfo+json");
                    _httpClient.getHttpClient().SetHeader(headers);

                    HttpResponse response = _httpClient.getHttpClient().Execute(url, "PUT", bytes);

                    //When sending build info, Expecting for NoContent (204) response from Artifactory
                    if (response._statusCode != HttpStatusCode.NoContent)
                    {
                        throw new WebException("Failed to send build info:" + response._message);
                    }
                }
            }
            catch (Exception we)
            {
                _log.Error(we.Message, we);
                throw new WebException("Exception in Uploading BuildInfo: " + we.Message, we);
            }
        }
开发者ID:jroquelaure,项目名称:tfs-plugin-artifactory,代码行数:28,代码来源:ArtefactDeployer.cs


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