Я так понял, что это из-за того, этот string не имеет функции ToString, которая возращает строку, а имеет ту ToString, которая возращает System.ToString[]
вот код интерфейса
using Application_windows_form.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Application_windows_form
{
public partial class Content_Type_Responce : Form
{
public Content_Type_Responce()
{
InitializeComponent();
}
async private void Button_request_click(object sender, EventArgs e)
{
Responce responce = await Core.Core.Recuest(textBox1.Text, Type_Request_Button.Text);
Content_Type_lable.Text = responce.Content_Type;
Server_label.Text = responce.Server;
Data_lable.Text = responce.Data;
Body_lable.Text = responce.Body;
}
}
}
Код ядра
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Application_windows_form.Core
{
static class Core
{
async public static Task<Responce> Recuest(string url, string method)
{
HttpRequestMessage req;
HttpClient client = new HttpClient();
Responce ErrorRes = new Responce() { Content_Type = "None", Body = "None", Server = "None", Data = "None" };
switch (method) {
case "Get":
req = new HttpRequestMessage(HttpMethod.Get, url);
break;
case "Post":
req = new HttpRequestMessage(HttpMethod.Post, url);
break;
case "Put":
req = new HttpRequestMessage(HttpMethod.Put, url);
break;
case "Delete":
req = new HttpRequestMessage(HttpMethod.Delete, url);
break;
default:
return ErrorRes;
}
HttpResponseMessage res = await client.SendAsync(req);
if (res.StatusCode.ToString() != "OK")
return ErrorRes;
Dictionary<string, string> data = await ResponceInfo(res);
Responce OkRes = new Responce() { Content_Type = data["Content-Type"], Body = data["Body"], Data = data["Date"], Server = data["Server"] };
return OkRes;
}
private async static Task<Dictionary<string, string>> ResponceInfo(HttpResponseMessage res)
{
Dictionary<string, string> info = new Dictionary<string, string>() { {"Date", "None"}, {"Content-Type", "None"}, {"Server", "None"} };
info.Add("Body", await res.Content.ReadAsStringAsync());
if (res.Headers.Contains("Date"))
info["Date"] = res.Headers.GetValues("Date").ToString();
if (res.Content.Headers.Contains("Content-Type"))
info["Content-Type"] = res.Content.Headers.GetValues("Content-Type").ToString();
if (res.Headers.Contains("Server"))
info["Server"] = res.Headers.GetValues("Server").ToString();
return info;
}
}
}
Класс Responce
internal class Responce
{
public string Content_Type;
public string Server;
public string Data;
public string Body;
}