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

C# Headers.NameValueHeaderValue类代码示例

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

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



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

示例1: NameValueHeaderValue

        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Debug.Assert(source != null);

            _name = source._name;
            _value = source._value;
        }
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:NameValueHeaderValue.cs


示例2: NameValueHeaderValue

        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Contract.Requires(source != null);

            _name = source._name;
            _value = source._value;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:NameValueHeaderValue.cs


示例3: RenameAsset

        public async void RenameAsset(IAsset asset, string newName)
        {
            // Create the request
            var client = new HttpClient();
            var resource = string.Format("https://wamsbluclus001rest-hs.cloudapp.net/API/Assets('{0}')", asset.Id);
            var request = new HttpRequestMessage(new HttpMethod("MERGE"), resource);

            // Set the request content
            var content = string.Format("{{ 'Name' : '{0}' }}", newName);
            var stringContent = new StringContent(content, Encoding.UTF8, "application/json");
            var oDataParameter = new NameValueHeaderValue("odata", "verbose");
            stringContent.Headers.ContentType.Parameters.Add(oDataParameter);
            request.Content = stringContent;
            
            // Set the request headers
            var jsonAccessToken = await this.GetAccessToken();
            string accessToken = JsonConvert.DeserializeObject<dynamic>(jsonAccessToken).access_token.Value;
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            request.Headers.Add("DataServiceVersion", "3.0");
            request.Headers.Add("MaxDataServiceVersion", "3.0");
            request.Headers.Add("x-ms-version", "1.0");
            request.Headers.Host = "wamsbluclus001rest-hs.cloudapp.net";
            var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
            mediaType.Parameters.Add(oDataParameter);
            client.DefaultRequestHeaders.Accept.Add(mediaType);

            // Make the request
            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();
        }
开发者ID:AppliedIS,项目名称:wams-preview,代码行数:30,代码来源:RestServices.cs


示例4: NameValueHeaderValue

        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Contract.Requires(source != null);

            this.name = source.name;
            this.value = source.value;
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:NameValueHeaderValue.cs


示例5: CheckValidParsedValue

 private void CheckValidParsedValue(string input, int startIndex, NameValueHeaderValue expectedResult,
     int expectedIndex)
 {
     HttpHeaderParser parser = GenericHeaderParser.MultipleValueNameValueParser;
     object result = null;
     Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
         string.Format("TryParse returned false: {0}", input));
     Assert.Equal(expectedIndex, startIndex);
     Assert.Equal(result, expectedResult);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:NameValueParserTest.cs


示例6: Ctor_ValidArguments

		public void Ctor_ValidArguments ()
		{
			NameValueHeaderValue nvh;
			
			nvh = new NameValueHeaderValue ("arg", "~");
			Assert.AreEqual ("~", nvh.Value, "#1");
			
			nvh = new NameValueHeaderValue ("arg", "\"\x7f\x80\"");
			Assert.AreEqual ("\"\x7f\x80\"", nvh.Value, "#2");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:10,代码来源:NameValueHeaderValueTest.cs


示例7: Equals

		public void Equals ()
		{
			var value = new NameValueHeaderValue ("ab");
			Assert.AreEqual (value, new NameValueHeaderValue ("ab"), "#1");
			Assert.AreEqual (value, new NameValueHeaderValue ("AB"), "#2");
			Assert.AreNotEqual (value, new NameValueHeaderValue ("AA"), "#3");
			Assert.AreEqual (value, new NameValueHeaderValue ("AB", ""), "#3-1");

			value = new NameValueHeaderValue ("ab", "DD");
			Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "DD"), "#4");
			Assert.AreNotEqual (value, new NameValueHeaderValue ("AB"), "#5");
			Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "dd"), "#6");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:NameValueHeaderValueTest.cs


示例8: ToString_UseNoValueAndTokenAndQuotedStringValues_SerializedCorrectly

        public void ToString_UseNoValueAndTokenAndQuotedStringValues_SerializedCorrectly()
        {
            NameValueHeaderValue nameValue = new NameValueHeaderValue("text", "token");
            Assert.Equal("text=token", nameValue.ToString());

            nameValue.Value = "\"quoted string\"";
            Assert.Equal("text=\"quoted string\"", nameValue.ToString());

            nameValue.Value = null;
            Assert.Equal("text", nameValue.ToString());

            nameValue.Value = string.Empty;
            Assert.Equal("text", nameValue.ToString());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:14,代码来源:NameValueHeaderValueTest.cs


示例9: Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc

        public void Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc()
        {
            NameValueWithParametersHeaderValue nameValue1 = new NameValueWithParametersHeaderValue("text", "value");
            NameValueWithParametersHeaderValue nameValue2 = new NameValueWithParametersHeaderValue("text", "value");
            NameValueHeaderValue nameValue3 = new NameValueHeaderValue("text", "value");

            // NameValueWithParametersHeaderValue just calls methods of the base class. Just verify Parameters is used.
            Assert.True(nameValue1.Equals(nameValue2), "No parameters.");
            Assert.False(nameValue1.Equals(null), "Compare to null.");
            Assert.False(nameValue1.Equals(nameValue3), "Compare to base class instance.");

            nameValue1.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            Assert.False(nameValue1.Equals(nameValue2), "none vs. 1 parameter.");

            nameValue2.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            Assert.True(nameValue1.Equals(nameValue2), "1 parameter vs. 1 parameter.");
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:17,代码来源:NameValueWithParametersHeaderValueTest.cs


示例10: Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwritten

        public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwritten()
        {
            MediaTypeWithQualityHeaderValue mediaType = new MediaTypeWithQualityHeaderValue("text/plain");

            NameValueHeaderValue quality = new NameValueHeaderValue("q", "0.132");
            mediaType.Parameters.Add(quality);
            Assert.Equal(1, mediaType.Parameters.Count);
            Assert.Equal("q", mediaType.Parameters.First().Name);
            Assert.Equal(0.132, mediaType.Quality);

            mediaType.Quality = 0.9;
            Assert.Equal(0.9, mediaType.Quality);
            Assert.Equal(1, mediaType.Parameters.Count);
            Assert.Equal("q", mediaType.Parameters.First().Name);

            mediaType.Parameters.Remove(quality);
            Assert.Null(mediaType.Quality);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:18,代码来源:MediaTypeWithQualityHeaderValueTest.cs


示例11: WriteToStreamAsync

        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            var boundry = Guid.NewGuid().ToString();
            var multipartFormDataContent = new MultipartContent("mixed", boundry);

            //content. .StatusCode = (int)System.Net.HttpStatusCode.OK;
            var contentType = new MediaTypeHeaderValue("multipart/mixed"); // String.Format("multipart/mixed; boundary={0}", boundry));
            var boundaryParameter = new NameValueHeaderValue("boundary", boundry);
            contentType.Parameters.Add(boundaryParameter);
            contentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("revision", "0.1"));
            content.Headers.ContentType = contentType;
            //content.Headers.Add("Accept", "multipart/mixed");
            //content.Headers.Add("MIME-Version", "1.0");

            var entities = (IEnumerable<object>)value;
            foreach (var entity in entities)
            {
                var entityContent = new ObjectContent<object>(entity, new JsonMediaTypeFormatter());
                entityContent.Headers.LastModified = DateTime.UtcNow; // Add("Last-Modified", entity.LastModified.ToUniversalTime().ToString("R"));
                entityContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-" + entity.GetType().Name);
                multipartFormDataContent.Add(entityContent);
            }
            return multipartFormDataContent.CopyToAsync(writeStream);
        }
开发者ID:joshcodes,项目名称:JoshCodes.Web,代码行数:24,代码来源:MultipartMediaTypeFormatter.cs


示例12: CheckValue

 private static void CheckValue(string value)
 {
     NameValueHeaderValue nameValue = new NameValueHeaderValue("text", value);
     Assert.Equal(value, nameValue.Value);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:NameValueHeaderValueTest.cs


示例13: CheckValidTryParse

 private void CheckValidTryParse(string input, NameValueHeaderValue expectedResult)
 {
     NameValueHeaderValue result = null;
     Assert.True(NameValueHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:NameValueHeaderValueTest.cs


示例14: CheckValidParse

 private void CheckValidParse(string input, NameValueHeaderValue expectedResult)
 {
     NameValueHeaderValue result = NameValueHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:NameValueHeaderValueTest.cs


示例15: Ctor_NameEmpty_Throw

 public void Ctor_NameEmpty_Throw()
 {
     // null and empty should be treated the same. So we also throw for empty strings.
     Assert.Throws<ArgumentException>(() => { NameValueHeaderValue nameValue = new NameValueHeaderValue(string.Empty); });
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:NameValueHeaderValueTest.cs


示例16: Clone_Call_CloneFieldsMatchSourceFields

 public void Clone_Call_CloneFieldsMatchSourceFields()
 {
     NameValueHeaderValue source = new NameValueHeaderValue("name", "value");
     NameValueHeaderValue clone = (NameValueHeaderValue)((ICloneable)source).Clone();
     Assert.Equal(source.Name, clone.Name);
     Assert.Equal(source.Value, clone.Value);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:NameValueHeaderValueTest.cs


示例17: Equals_NameUseDifferentCasing_ConsideredEqual

 public void Equals_NameUseDifferentCasing_ConsideredEqual()
 {
     NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
     NameValueHeaderValue nameValue2 = new NameValueHeaderValue("TEXT");
     Assert.True(nameValue1.Equals(nameValue2), "text vs. TEXT.");
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:NameValueHeaderValueTest.cs


示例18: Properties

		public void Properties ()
		{
			var value = new NameValueHeaderValue ("s", "p");
			Assert.AreEqual ("s", value.Name, "#1");
			Assert.AreEqual ("p", value.Value, "#2");

			value = new NameValueHeaderValue ("s");
			Assert.AreEqual ("s", value.Name, "#3");
			Assert.IsNull (value.Value, "#4");

			value.Value = "bb";
			Assert.AreEqual ("bb", value.Value, "#5");

			value.Value = null;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:15,代码来源:NameValueHeaderValueTest.cs


示例19: Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc

        public void Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc()
        {
            NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
            NameValueHeaderValue nameValue2 = new NameValueHeaderValue("text");

            nameValue1.Value = null;
            nameValue2.Value = null;
            Assert.True(nameValue1.Equals(nameValue2), "<null> vs. <null>.");

            nameValue1.Value = "token";
            nameValue2.Value = null;
            Assert.False(nameValue1.Equals(nameValue2), "token vs. <null>.");

            nameValue1.Value = null;
            nameValue2.Value = "token";
            Assert.False(nameValue1.Equals(nameValue2), "<null> vs. token.");

            nameValue1.Value = string.Empty;
            nameValue2.Value = "token";
            Assert.False(nameValue1.Equals(nameValue2), "string.Empty vs. token.");

            nameValue1.Value = null;
            nameValue2.Value = string.Empty;
            Assert.True(nameValue1.Equals(nameValue2), "<null> vs. string.Empty.");

            nameValue1.Value = "token";
            nameValue2.Value = "TOKEN";
            Assert.True(nameValue1.Equals(nameValue2), "token vs. TOKEN.");

            nameValue1.Value = "token";
            nameValue2.Value = "token";
            Assert.True(nameValue1.Equals(nameValue2), "token vs. token.");

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"QUOTED STRING\"";
            Assert.False(nameValue1.Equals(nameValue2), "\"quoted string\" vs. \"QUOTED STRING\".");

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"quoted string\"";
            Assert.True(nameValue1.Equals(nameValue2), "\"quoted string\" vs. \"quoted string\".");

            Assert.False(nameValue1.Equals(null), "\"quoted string\" vs. <null>.");
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:43,代码来源:NameValueHeaderValueTest.cs


示例20: GetHashCode_NameUseDifferentCasing_HashDiffersAccordingToRfc

 public void GetHashCode_NameUseDifferentCasing_HashDiffersAccordingToRfc()
 {
     NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
     NameValueHeaderValue nameValue2 = new NameValueHeaderValue("TEXT");
     Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:NameValueHeaderValueTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Headers.Token类代码示例发布时间:2022-05-26
下一篇:
C# Headers.MediaTypeWithQualityHeaderValue类代码示例发布时间: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