如何获取 httpStatusCode 200 的描述?

How to get a description of the httpStatusCode 200?

我在Visual Studio

中有以下代码
using System;
using System.Windows.Forms;
using System.Net.Http;
using System.Web;
using System.Net;
using System.IO;

namespace Xml_Trial
{
    public partial class Form1 : Form
    {
        public Form1()
        { 
           InitializeComponent();
        }

        private void LoadUrl_click(object sender, EventArgs e)
        {
            Xmlcheck(TxtUrl.Text);
        }

        private static async void Xmlcheck(string TxtUrl)
        {
            try
            {
                HttpClient client = new HttpClient() ; //httpclient
                var request = new HttpRequestMessage(HttpMethod.Get, TxtUrl);
                HttpResponseMessage response = await client.GetAsync(request.RequestUri);
                 if (response.StatusCode == HttpStatusCode.OK) 
                    {
                       // Console.WriteLine((int)response.StatusCode); More code here
                    }
                response.Dispose();
            } 
            catch (HttpRequestException e)
            {
               MessageBox.Show(e.Message);
            }
        }
    }

}

我已经这样写代码来获取200状态码Console.WriteLine((int)response.StatusCode) 还有什么代码可以从 httpstatuscode 描述中获得更多信息,而不仅仅是“OK”或“200”....

我相信您正在寻找 ReasonPhrase 属性,这是“通常由服务器与状态代码一起发送的原因短语”。

例如:

Console.WriteLine($"{(int)response.StatusCode} {response.ReasonPhrase}");

此处列出了所有有效状态代码(包括我最喜欢的 418)及其默认原因短语:HTTP response status codes