本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}