【解決方法】http 応答を JSON オブジェクトとして返す WebException VS を解決するにはどうすればよいですか

プログラミングQA


プロキシ上で、JSON 形式で HTTP 応答を返すメソッドの呼び出し中に WebException が発生しました。

エラーは次のとおりです。

Server Error in '/' Application.
404
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: 404

Source Error:

Line 44:             else
Line 45:             {
Line 46:                 throw new WebException(((int)response.StatusCode).ToString());
Line 47:             }
Line 48:         }

私が試したこと:

private T GetResult<T>(HttpResponseMessage response)
        {
            if (response.IsSuccessStatusCode)   // code 200
            {
                var content = response.Content.ReadAsStringAsync().Result;   
                return JsonConvert.DeserializeObject<T>(content);
            }
            else
            {
                throw new WebException(((int)response.StatusCode).ToString());
            }
        }

解決策 1

404 ポイントが無許可なので、Postman をダウンロードして、最初に試してみます。 コードの前にそれを試してください

コメント

タイトルとURLをコピーしました