我有一个相当简单的问题,我想对于大脑来说,这很容易解决。这只是在谷歌上尝试了一下不同的查询,什么也没有出现,但嘿,这就是我来这里的原因。
下面是错误: System.InvalidOperationException
基本上,这里的这段代码抛出了这个错误
string test = response.Content.Headers.GetValues("Location").FirstOrDefault();Fiddler中的位置如下所示:
位置:https://www.redirecturlishere.com/blah
下面是整个函数:
private async Task<string> GetRequest()
{
//HttpContent postContent = new StringContent(post, Encoding.ASCII, "application/x-www-form-urlencoded");
using (HttpResponseMessage response = await httpClient.GetAsync(
"http://www.cant-share-url.com"))
{
using (HttpContent content = response.Content)
{
string test = response.Content.Headers.GetValues("Location").FirstOrDefault();
}
}
return "";
}有关错误的更多详细信息,“附加信息:错误使用的标头名称。请确保将请求标头用于HttpRequestMessage,将响应标头用于HttpResponseMessage,将内容标头用于HttpContent对象。”
我不认为有太多其他的东西要解释,所以我就到此为止。
发布于 2014-09-11 00:25:24
我已经基本上解决了标题没有存储在内容中的问题,愚蠢的我。
对于任何看不到解决方案的人来说。:)
string test = response.Headers.GetValues("Location").FirstOrDefault()https://stackoverflow.com/questions/25770469
复制相似问题