QiFeng.ZWY.Utility/HttpClientHelper.cs

(开头部分) 8KB

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

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace QiFeng.LMSD.Utility
{
    public class HttpClientHelper
    {
 
        public static string Request(string url, string data, string method)
        {
            string str = null;
            using (HttpClient client = new HttpClient())
            {
                HttpContent content;
                HttpResponseMessage result = new HttpResponseMessage();
                byte[] bytes = Encoding.UTF8.GetBytes(data);
      
                if (method == "POST")
                {
                    content = new StringContent(data)
                    {
                        Headers = { ContentType = new MediaTypeHeaderValue("application/json") }
                    };
                    result = client.PostAsync(url, content).Result;
                }
                else if (method == "GET")
                {
                    result = client.GetAsync(url).Result;
                }
                else if (method == "PUT")
                {
                    Stream stream = new MemoryStream();
                    stream.Write(bytes, 0, bytes.Length);
                    content = new StreamContent(stream);
                    result = client.PutAsync(url, content).Result;
                }
                else if (method == "DELETE")
                {
                    result = client.DeleteAsync(url).Result;
                }
                if (result.IsSuccessStatusCode)
                {
                    str = result.Content.ReadAsStringAsync().Result;
                }
                else
                {
                    str = result.ToString();
                }
            }
            return str.Trim();
后面还有 190 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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