簡體   English   中英

HttpResponseMessage System.InvalidOperationException

[英]HttpResponseMessage System.InvalidOperationException

我認為,這是一個很簡單的問題,很容易解決。 只是嘗試了一次在Google上進行的其他查詢,但沒有彈出任何提示,但這就是為什么我在這里。

這是錯誤: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對象一起使用。”

我認為沒有太多要解釋的了,因此我將其保留。

我已經解決了問題,基本上標題沒有存儲在內容中,愚蠢的我。

對於任何看不到解決方案的人。 :)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM