本文整理汇总了C#中System.Net.Http.Headers.NameValueHeaderValue类的典型用法代码示例。如果您正苦于以下问题:C# NameValueHeaderValue类的具体用法?C# NameValueHeaderValue怎么用?C# NameValueHeaderValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameValueHeaderValue类属于System.Net.Http.Headers命名空间,在下文中一共展示了NameValueHeaderValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameValueHeaderValue
protected NameValueHeaderValue(NameValueHeaderValue source)
{
Debug.Assert(source != null);
_name = source._name;
_value = source._value;
}
示例2: NameValueHeaderValue
protected NameValueHeaderValue(NameValueHeaderValue source)
{
Contract.Requires(source != null);
_name = source._name;
_value = source._value;
}
示例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();
}
示例4: NameValueHeaderValue
protected NameValueHeaderValue(NameValueHeaderValue source)
{
Contract.Requires(source != null);
this.name = source.name;
this.value = source.value;
}
示例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);
}
示例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");
}
示例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");
}
示例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());
}
示例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.");
}
示例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);
}
示例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);
}
示例12: CheckValue
private static void CheckValue(string value)
{
NameValueHeaderValue nameValue = new NameValueHeaderValue("text", value);
Assert.Equal(value, nameValue.Value);
}
示例13: CheckValidTryParse
private void CheckValidTryParse(string input, NameValueHeaderValue expectedResult)
{
NameValueHeaderValue result = null;
Assert.True(NameValueHeaderValue.TryParse(input, out result));
Assert.Equal(expectedResult, result);
}
示例14: CheckValidParse
private void CheckValidParse(string input, NameValueHeaderValue expectedResult)
{
NameValueHeaderValue result = NameValueHeaderValue.Parse(input);
Assert.Equal(expectedResult, result);
}
示例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); });
}