【发布时间】:2014-08-22 04:12:21
【问题描述】:
我正在进行 HTTP 调用。我的响应在HttpResponseMessage 对象的标题部分中包含会话代码X-BB-SESSION。如何获取特定的标头值?
我正在使用 foreach 语句遍历所有标题 (MSDN link)。但是编译器一直说它无法完成:
foreach statement cannot operate on variables of type
System.net.http.headers.cachecontrolheadervalue because
'System.net.http.headers.cachecontrolheadervalue' doesn't contain
a public definition for 'GetEnumerator'
这是我正在尝试的代码:
//Connection code to BaasBox
HttpResponseMessage response = await client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
//get the headers
HttpResponseHeaders responseHeadersCollection = response.Headers;
foreach (var value in responseHeadersCollection.CacheControl) --> HERE
{
string sTemp = String.Format("CacheControl {0}={1}", value.Name, value.Value);
} else
{
Console.WriteLine("X-BB-SESSION: NOT Found");
}
我试图从中获取值的标题内容(X-BB-SESSION 值)类似于:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With
X-BB-SESSION: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
【问题讨论】:
-
你不是说windows phone 8.1吗?
-
可能是 WP 8 或 WP 8.1 当我开始做测试时,它是在 WP8 中。现在有了自动更新,我有 WP 8.1 但是,相同的代码在此之前一直在工作(以获得特定的标题)
标签: c# windows-phone-8 httpclient httpresponse baasbox