首页 文章

HttpResponseMessage System.InvalidOperationException

提问于
浏览
0

我认为很容易解决的一个简单的问题我认为是大脑 . 这只是在谷歌尝试了不同的查询,没有任何突然出现,但嘿,这就是我在这里的原因 .

这是错误: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对象一起使用 . ”

我认为还有很多其他问题无法解释,所以我会留下它 .

1 回答

  • 0

    我已经解决了问题基本上 Headers 没有存储在内容中,傻我 .

    对于任何没有看到解决方案的人 . :)

    string test = response.Headers.GetValues("Location").FirstOrDefault()
    

相关问题