本文整理汇总了C#中System.Net.Http.Headers.HttpRequestHeaders.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestHeaders.Add方法的具体用法?C# HttpRequestHeaders.Add怎么用?C# HttpRequestHeaders.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.Headers.HttpRequestHeaders
的用法示例。
在下文中一共展示了HttpRequestHeaders.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyRequestHeaders
public static void CopyRequestHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>> source,
HttpRequestHeaders destination)
{
foreach (var header in source)
{
switch (header.Key)
{
case "User-Agent":
destination.Add(header.Key, "dev/1.0");
break;
case "Via":
break;
default:
destination.Add(header.Key, String.Join(",", header.Value));
break;
}
}
}
示例2: Populate
internal void Populate(HttpRequestHeaders headers)
{
if (this.CacheControl != null)
{
headers.Add("response-cache-control", this.CacheControl);
}
if (this.ContentDisposition != null)
{
headers.Add("response-content-disposition", this.ContentDisposition);
}
if (this.ContentEncoding != null)
{
headers.Add("response-content-encoding", this.ContentEncoding);
}
if (this.ContentLanguage != null)
{
headers.Add("response-content-language", this.ContentLanguage);
}
if (this.ContentType != null)
{
headers.Add("response-content-type", this.ContentType);
}
if (this.Expires != null)
{
headers.Add("response-expires", this.Expires);
}
}
示例3: SetHeaders
// I would have prefered to return a list of headers instead of relying on a side effect,
// but I was having problems getting the accept header to work properly. If anyone has any
// refactoring ideas, I'm listening...
public void SetHeaders(HttpRequestHeaders headers)
{
headers.Add(Constants.AuthorizationHeaderName, this.AuthorizationHeader());
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
示例4: SetHeaders
/// <summary>
/// Resets the headers to make any request to the Nexon Api look legit
/// </summary>
/// <param name="headers">The <see cref="HttpRequestHeaderCollection" /> that gets modified</param>
private static void SetHeaders(HttpRequestHeaders headers)
{
headers.Clear();
headers.Accept.ParseAdd("application/json, text/javascript, */*; q=0.01");
headers.AcceptEncoding.ParseAdd("gzip,deflate");
headers.AcceptLanguage.ParseAdd("en-GB,en-us;q=0.8,en;q=0.6");
headers.UserAgent.ParseAdd(GetUserAgent);
headers.Connection.TryParseAdd("keep-alive");
headers.Host = new Uri(LoginUrl).Host;
headers.Add("X-Requested-With", "XMLHttpRequest");
}
示例5: AddAuthenticationHeaders
/// <summary>
/// Adds the user name and password as http headers elements for the corresponding bulk file upload operation.
/// </summary>
/// <param name="requestHeaders">The headers collection to which authentication requests should be added.</param>
protected internal override void AddAuthenticationHeaders(HttpRequestHeaders requestHeaders)
{
requestHeaders.Add("UserName", _username);
requestHeaders.Add("Password", _password);
}
示例6: UpdateHeaders
private void UpdateHeaders( HttpRequestHeaders headers ) {
headers.Add( "PddToken", PddToken );
headers.Authorization = AuthenticationHeaderValue.Parse( $"OAuth {AuthToken.Token}" );
}
示例7: AddAuthenticationHeaders
/// <summary>
/// Adds the AuthenticationToken header element for the corresponding bulk file upload operation.
/// </summary>
/// <param name="requestHeaders">The headers collection to which authentication requests should be added.</param>
protected internal override void AddAuthenticationHeaders(HttpRequestHeaders requestHeaders)
{
if (OAuthTokens == null)
{
throw new InvalidOperationException(ErrorMessages.GetFullOAuthAccessTokenNotRequestedMessage(GetType()));
}
requestHeaders.Add("AuthenticationToken", OAuthTokens.AccessToken);
}
示例8: TransferHeaders
private Task TransferHeaders(IHeaderDictionary sourceHeaders, HttpRequestHeaders destinationHeaders)
{
destinationHeaders.Add("Accept", sourceHeaders.ContainsKey("Accept")
? sourceHeaders["Accept"].ToString()
: "image/*");
destinationHeaders.Add("Accept-Encoding", sourceHeaders.ContainsKey("Accept-Encoding")
? sourceHeaders["Accept-Encoding"].ToString()
: string.Empty);
destinationHeaders.Add("X-Frame-Options", _defaultHeaders["X-Frame-Options"]);
destinationHeaders.Add("X-XSS-Protection", _defaultHeaders["X-XSS-Protection"]);
destinationHeaders.Add("X-Content-Type-Options", _defaultHeaders["X-Content-Type-Options"]);
//destinationHeaders.Add("Content-Security-Policy", _defaultHeaders["Content-Security-Policy"]);
return Task.FromResult(0);
}