0
非常简单的问题,我已经很容易解决,我认为大脑。这只是一个尝试了不同的谷歌查询,没有什么弹出,但嘿,这就是为什么我在这里。HttpResponseMessage System.InvalidOperationException
以下是错误: System.InvalidOperationException
基本上这个错误是在这片这里代码抛出
string test = response.Content.Headers.GetValues("Location").FirstOrDefault();
位置在提琴手是这样的:
地点: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 "";
}
有关错误的更多详细信息,“附加信息:错误的标题名称。确保请求头用于与HttpResponseMessage HttpRequestMessage,响应头和内容头部与HttpContent对象。”
我不认为有其他东西来解释,所以我会留在这。
有你在调试器查了一下'响应.Content.Headers.GetValues(“Location”)'返回,如果它返回null你会得到一个'InvalidOperationException' – 2014-09-10 16:25:10
@BenRobinson真的吗?它不会抛出'NullReferenceException',但会抛出'InvalidOperationException'? – Michael 2014-09-10 16:32:08