本文整理汇总了C#中System.Net.WebHeaderCollection.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.GetKey方法的具体用法?C# WebHeaderCollection.GetKey怎么用?C# WebHeaderCollection.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebHeaderCollection
的用法示例。
在下文中一共展示了WebHeaderCollection.GetKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHeadersDictionaryFrom
private static Dictionary<string, string> GetHeadersDictionaryFrom(WebHeaderCollection headers)
{
string pattern = "\\s+";
Dictionary<string, string> dictionary = new Dictionary<string, string>();
for (int i = 0; i < headers.Keys.Count; i++)
{
string key = headers.GetKey(i).Replace("-", " ").ToUpper();
key = Regex.Replace(key, pattern, "");
string value = headers.Get(headers.GetKey(i));
//System.Console.WriteLine("Key => " + key + " Value => " + value);
dictionary.Add(key, value);
}
return dictionary;
}
示例2: HeadersToString
private string HeadersToString(WebHeaderCollection Headers)
{
string Output = string.Empty;
for (int i = 0; i < Headers.Count; i++)
{
Output += Headers.GetKey(i) + ": " + Headers[i] + "\r\n";
}
return Output;
}
示例3: MapHeaders
public Dictionary<string, string> MapHeaders(WebHeaderCollection headerCollection)
{
var headers = new Dictionary<string, string>();
for (var i = 0; i < headerCollection.Count; i++)
{
headers.Add(headerCollection.GetKey(i), string.Join(",", headerCollection.GetValues(i)));
}
return headers;
}
示例4: AddHeaders
public void AddHeaders(WebHeaderCollection headers)
{
if (headers != null)
{
Headers = new List<Header>();
for (int i = 0; i < headers.Count; ++i)
{
string header = headers.GetKey(i);
foreach (string value in headers.GetValues(i))
{
Headers.Add(new Header(header, value));
}
}
}
}
示例5: 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);
}
}
}
示例6: CanonicalizedUCloudHeaders
private static string CanonicalizedUCloudHeaders(WebHeaderCollection header)
{
string canoncializedUCloudHeaders = string.Empty;
SortedDictionary<string, string> headerMap = new SortedDictionary<string, string> ();
for (int i = 0; i < header.Count; ++i) {
string headerKey = header.GetKey (i);
if (headerKey.ToLower().StartsWith ("x-ucloud-")) {
foreach (string value in header.GetValues(i)) {
if (headerMap.ContainsKey (headerKey)) {
headerMap [headerKey] += value;
headerMap [headerKey] += @",";
} else {
headerMap.Add (headerKey, value);
}
}
}
}
foreach (KeyValuePair<string, string> item in headerMap) {
canoncializedUCloudHeaders += (item.Key + @":" + item.Value + @"\n");
}
return canoncializedUCloudHeaders;
}
示例7: FormatHeaders
static string FormatHeaders (WebHeaderCollection headers)
{
var sb = new StringBuilder();
for (int i = 0; i < headers.Count ; i++) {
string key = headers.GetKey (i);
if (WebHeaderCollection.AllowMultiValues (key)) {
foreach (string v in headers.GetValues (i)) {
sb.Append (key).Append (": ").Append (v).Append ("\r\n");
}
} else {
sb.Append (key).Append (": ").Append (headers.Get (i)).Append ("\r\n");
}
}
return sb.Append("\r\n").ToString();
}
示例8: HandleHeader
/// <summary>
/// Handle response headers
/// </summary>
private void HandleHeader(string url, WebHeaderCollection headers)
{
for (int i = 0; i < headers.Count; i++)
{
string Key = headers.GetKey(i);
string Value = headers.Get(i);
switch (Key)
{
case "Set-Cookie":
HandleResponseSetCookie(url, Value);
break;
case "Location":
this.RedirectLocation = Value;
break;
}
}
}
示例9: Test_WebHeader_02
public static void Test_WebHeader_02()
{
string file = @"http\header_01.json";
string file2 = @"http\header_02.json";
file = zPath.Combine(_directory, file);
file2 = zPath.Combine(_directory, file2);
WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("xxx", "yyy");
headers.Add("xxx", "yyy222");
headers.Add("zzz", "fff");
headers.Add("yyy", "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);
}
}
//headers.zSave(file);
BsonDocument doc = headers.ToBsonDocument();
doc.zSave(file);
}
示例10: FillResponseHeader
/// <summary>
/// Fills the Response Header Collection.
/// </summary>
/// <param name="resp"> The ResponseBuffer type.</param>
/// <param name="request"> The HttpWebRequest type.</param>
/// <param name="responseHeaders"> The Response WebHeaderCollection.</param>
/// <param name="hwr"> The HttpWebResponse type.</param>
/// <returns> An updated ResponseBuffer type containing the change.</returns>
public static ResponseBuffer FillResponseHeader(ResponseBuffer resp,HttpWebRequest request, WebHeaderCollection responseHeaders, HttpWebResponse hwr)
{
Hashtable coll = new Hashtable();
coll.Add("Character Set",hwr.CharacterSet);
coll.Add("Content Encoding",hwr.ContentEncoding);
coll.Add("Last Modified",hwr.LastModified);
coll.Add("Method",hwr.Method);
coll.Add("Protocol Version",hwr.ProtocolVersion);
coll.Add("Response Uri",hwr.ResponseUri);
coll.Add("Server",hwr.Server);
coll.Add("Status Code",hwr.StatusCode);
coll.Add("Status Description",hwr.StatusDescription);
coll.Add("Referer", request.Referer);
for (int i = 0;i<responseHeaders.Count;i++)
{
if (!coll.ContainsKey(responseHeaders.GetKey(i)) )
{
coll.Add(responseHeaders.GetKey(i), responseHeaders[i]);
}
}
StringBuilder sb = new StringBuilder();
sb.Append("---------------------");
sb.Append("=RESPONSE HEADERS=");
sb.Append("---------------------\r\n");
foreach (DictionaryEntry de in coll)
{
sb.Append(de.Key);
sb.Append(":");
sb.Append(de.Value);
sb.Append("\r\n");
}
resp.ResponseHeader = sb.ToString();
resp.ResponseHeaderCollection = coll;
return resp;
}
示例11: GetRedirectHeaders
/// <summary>
/// Receives the continue header from delegate and sets it to ContinueHeader property.
/// </summary>
/// <param name="statusCode"> The status code</param>
/// <param name="header"> The header collection.</param>
protected void GetRedirectHeaders(int statusCode, WebHeaderCollection header)
{
StringBuilder textStream = new StringBuilder();
for (int i = 0;i<header.Count;i++)
{
textStream.Append(header.GetKey(i));
textStream.Append(": ");
textStream.Append(header.Get(i));
textStream.Append("\r\n");
}
ContinueHeader= textStream.ToString();
}
示例12: ResetCookie
public void ResetCookie(WebHeaderCollection whc, string host)
{
for (int i = 0; i < whc.Count; i++) {
string key = whc.GetKey(i);
string value = whc.Get(i);
if (key == "Set-Cookie") {
Match match = Regex.Match(value, "(.+?)=(.+?);");
if (match.Captures.Count > 0) {
cookieContainer.Add(new Cookie(match.Groups[1].Value, match.Groups[2].Value, "/", host.Split(':')[0]));
}
}
}
}
示例13: HTTPFetch
public static string HTTPFetch(string url, string method,
WebHeaderCollection headers,
byte[] streamBytes,
int contentLength,
out string[] responseFields,
string contentType = "application/x-www-form-urlencoded",
string requestAccept = null,
string host = null)
{
_active = true;
try
{
var uri = new Uri(url);
if (EndpointCallback != null) EndpointCallback(uri.AbsolutePath);
if (string.IsNullOrEmpty(host)) host = uri.Host;
string reqStr =
String.Format("{0} {1} HTTP/1.1\r\n", method, url) +
String.Format("Host: {0}\r\n", host) +
String.Format("Connection: Close\r\n");
if (!IsNullOrWhiteSpace(requestAccept))
reqStr += String.Format("Accept: {0}\r\n", requestAccept);
if (contentType != null)
reqStr += String.Format("Content-Type: {0}\r\n", contentType);
if (headers != null)
{
for (int i = 0; i < headers.Count; ++i)
{
string header = headers.GetKey(i);
foreach (string value in headers.GetValues(i))
{
reqStr += String.Format("{0}: {1}\r\n", header, value);
}
}
}
reqStr += String.Format("Content-Length: {0}\r\n", contentLength);
reqStr += "\r\n";
byte[] headerBytes = ToByteArray(reqStr);
byte[] finalBytes = headerBytes;
if (contentLength > 0)
{
var requestBytes = new byte[headerBytes.Length + contentLength];
Buffer.BlockCopy(headerBytes, 0, requestBytes, 0, headerBytes.Length);
Buffer.BlockCopy(streamBytes, 0, requestBytes, headerBytes.Length, contentLength);
finalBytes = requestBytes;
}
string responseFromServer = "";
responseFields = new string[] { };
var tcpClient = new TcpClient();
string responseStr = "";
int responseLength = 0;
if (url.ToLower().StartsWith("https"))
{
//HTTPS
tcpClient.Connect(uri.Host, 443);
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true);
//This has a bug on mono: Message "The authentication or decryption has failed."
//Therefore unfortunately we have to ignore certificates.
using (var s = new SslStream(tcpClient.GetStream(), false,
new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true)))
{
s.AuthenticateAsClient(uri.Host, null, SslProtocols.Tls, false);
if (UpstreamCallback != null && UpstreamCallbackRate > 0)
{
int i = 0;
while (i < finalBytes.Length)
{
if (!_active) throw new Exception("Halt");
if (i + _upstreamCallbackRate > finalBytes.Length)
{
s.Write(finalBytes, i, finalBytes.Length - i);
UpstreamCallback(contentLength, contentLength);
break;
}
s.Write(finalBytes, i, (int)_upstreamCallbackRate);
i += (int)_upstreamCallbackRate;
UpstreamCallback(Math.Min(i, contentLength), contentLength);
}
}
else s.Write(finalBytes, 0, finalBytes.Length);
s.Flush();
while (true)
{
var responseBytes = new byte[8192];
int i = s.Read(responseBytes, 0, responseBytes.Length);
if (i == 0) break;
responseStr += Encoding.UTF8.GetString(responseBytes, 0, i);
responseLength += i;
}
}
}
else
//.........这里部分代码省略.........
示例14: GetCookieString
private static string GetCookieString(WebHeaderCollection webHeaderCollection)
{
try
{
string CokString = "";
for (int i = 0; i < webHeaderCollection.Count; i++)
{
String header__ = webHeaderCollection.GetKey(i);
if (header__ != "Set-Cookie")
continue;
String[] values = webHeaderCollection.GetValues(header__);
if (values.Length < 1)
continue;
foreach (string v in values)
if (v != "")
CokString += MrHTTP.StripCokNameANdVal(v)+";";
}
if (CokString.Length > 0)
return CokString.Substring(0, CokString.Length - 1);
return CokString;
}
catch { return ""; }
}
示例15: ConvertHeaders
private static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ConvertHeaders(
WebHeaderCollection webHeaders)
{
for (var i = 0; i < webHeaders.Count; i++)
{
var key = webHeaders.GetKey(i);
yield return new KeyValuePair<string, IEnumerable<string>>(key, webHeaders.GetValues(i));
}
}