Yi.Framework.Net6/Yi.Framework.Common/Helper/HttpHelper.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Yi.Framework.Common.Helper
{
    public static class HttpHelper
    {

        public static HttpClient Client { get; set; } = new HttpClient();

        public static async Task<string> Get(string url)
        {
            return await Client.GetStringAsync(url);
        }

        public static async Task<Stream> GetIO(string url)
        {
            return await Client.GetStreamAsync(url);
        }


        public static async Task<string> Post(string url, object item = null, Dictionary<string, string> head = null)
        {

            using StringContent json = new(JsonSerializer.Serialize(item), Encoding.UTF8, MediaTypeNames.Application.Json);


            if (head is not null)
            {
                foreach (var d in head)
                {
                    json.Headers.Add(d.Key, d.Value);
                }
            }

            var httpResponse = await Client.PostAsync(url, json);

            httpResponse.EnsureSuccessStatusCode();

            var content = httpResponse.Content;

            return await content.ReadAsStringAsync();
        }


//        public static string HttpGet(string Url, string postDataStr="")
//        {
//#pragma warning disable SYSLIB0014 // 类型或成员已过时
//            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
//#pragma warning restore SYSLIB0014 // 类型或成员已过时
//            request.Method = "GET";
后面还有 62 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。