{"id":16964002,"url":"https://github.com/eva-ss/httplib","last_synced_at":"2025-10-13T12:22:46.040Z","repository":{"id":45517115,"uuid":"312543724","full_name":"EVA-SS/HttpLib","owner":"EVA-SS","description":"便捷的Http库","archived":false,"fork":false,"pushed_at":"2025-05-07T07:16:35.000Z","size":306,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-14T21:58:18.194Z","etag":null,"topics":["http","http-client","httpclient","httphelper","httplib"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EVA-SS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-13T10:25:32.000Z","updated_at":"2025-08-04T01:06:58.000Z","dependencies_parsed_at":"2024-03-21T10:13:27.649Z","dependency_job_id":"ce657447-1423-4f9e-84db-02d12791e938","html_url":"https://github.com/EVA-SS/HttpLib","commit_stats":null,"previous_names":["haku-men/httplib"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/EVA-SS/HttpLib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EVA-SS%2FHttpLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EVA-SS%2FHttpLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EVA-SS%2FHttpLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EVA-SS%2FHttpLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EVA-SS","download_url":"https://codeload.github.com/EVA-SS/HttpLib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EVA-SS%2FHttpLib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015049,"owners_count":26085643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-client","httpclient","httphelper","httplib"],"created_at":"2024-10-13T23:26:51.850Z","updated_at":"2025-10-13T12:22:46.023Z","avatar_url":"https://github.com/EVA-SS.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HttpLib 便捷的Http库 | 多线程下载库\n\n如果你喜欢 HttpLib 项目，请为本项点亮一颗星 ⭐！\n\n\n[![NuGet](https://img.shields.io/nuget/vpre/tom.httpLib?style=flat-square\u0026logo=nuget\u0026label=HttpLib)](https://www.nuget.org/packages/Tom.HttpLib)\n[![Download](https://img.shields.io/nuget/dt/Tom.HttpLib?style=flat-square)](https://www.nuget.org/packages/Tom.HttpLib)\n\n## 🖥支持环境\n- .NET 6.0及以上。\n- .NET Core3.1及以上。\n- .NET Standard2.0及以上。\n\n## 🌴支持\n\n#### multipart/form-data\n\n既可以上传文件等二进制数据，也可以上传表单键值对\n\n#### 上传与下载进度回调\n\n上传与下载的进度监控\n\n#### 支持缓存\n\n类似图片加载场景，同一个id的图片通过磁盘存储减少网络开支\n\n\n****\n\n## 目录\n* [示例](#示例)\n    * [创建请求](#创建请求)\n    * [添加参数](#添加参数)\n    * [添加请求头](#添加请求头)\n    * [设置代理](#设置代理)\n    * [启用重定向](#启用重定向)\n    * [设置超时时长](#设置超时时长)\n    * [设置编码](#设置编码)\n    * [设置缓存](#设置缓存)\n    * [请求之前处理](#请求之前处理)\n    * [注入回调获取进度](#注入回调获取进度)\n        * [上传](#上传)\n        * [下载](#下载)\n    * [请求](#请求)\n        * [异步错误](#异步错误)\n        * [异步请求](#异步请求)\n        * [同步获取](#同步获取)\n* [实例](#实例)\n* [实例下载文件](#实例下载文件)\n* [实例流式传输](#实例流式传输)\n* [实例获取域名IP](#实例获取域名IP)\n* [实例全局错误捕获](#实例全局错误捕获)\n* [ResultResponse介绍](#ResultResponse介绍)\n\n\n# 示例\n## 创建请求\n``` csharp\nHttp.Get(\"https://www.baidu.com\")\n```\n``` csharp\nHttp.Post(\"https://www.baidu.com\")\n```\n``` csharp\nHttp.Put(\"https://www.baidu.com\")\n```\n``` csharp\nHttp.Delete(\"https://www.baidu.com\")\n```\n### 添加参数\n\n\u003e GET请求参数会自动注入到地址\n\n``` csharp\ndata(\"wd\", \"随便搜一下\")\ndata(new { test1 = \"测试1\", test2 = \"测试2\" })\ndata(new { params_ = \"关键字参数\" })\ndata(new { wd = new string[] { \"GitHub - Haku-Men HttpLib\", \"POST数组参数\" } })\n```\n\n\u003e URL参数（除了GET请求）\n\n``` csharp\nquery(\"键\", \"值对\")\nquery(new { test = \"POST下继续传递URL参数\" })\n```\n\n``` csharp\ndata(new Val(\"test1\", \"测试1\"), new Val(\"test2\", \"测试2\"))\n```\n``` csharp\ndata(new List\u003cVal\u003e {\n\tnew Val(\"test1\",\"测试1\"),\n\tnew Val(\"test2\",\"测试2\")\n})\n```\n\n\u003e 上传字符串 默认 `text/plain`\n\n``` csharp\nstring json = \"{\\\"JSON\\\":\\\"json data\\\"}\";\ndatastr(json, \"application/json\")\n```\n\n\u003e 上传文件\n\n``` csharp\ndata(new Files(\"文件地址\"))\n```\n``` csharp\nfile(@\"文件地址\")\n```\n\n### 添加请求头\n``` csharp\nheader(\"Authorization\", \"abc\")\n```\n``` csharp\nheader(new { accept = \"*/*\", userAgent = \"Chrome\" })\n```\n``` csharp\nheader(new Val(\"accept\",\"*/*\"), new Val(\"user-agent\",\"Chrome\"))\n```\n\n### 设置代理\n``` csharp\nproxy(\"127.0.0.1\",1000)\n```\n\n### 启用重定向\n\u003e默认禁止\n``` csharp\nredirect()\n```\n\n### 设置超时时长\n\u003e`毫秒`（默认不超时）\n``` csharp\ntimeout(3000)\n```\n\n### 设置编码\n\u003e默认`utf-8`\n``` csharp\nencoding('utf-8')\n```\n\n## 设置缓存\n\u003e先配置`Config.CacheFolder`缓存文件夹\n``` csharp\ncache(\"缓存id\")\n```\n\u003e或者设定有效期 1分钟\n``` csharp\ncache(\"缓存id\",1)\n```\n\n### 请求之前处理\n``` csharp\nbefore((HttpWebResponse response, ResultResponse result) =\u003e\n{\n\treturn true; //继续请求\n})\n```\n\n### 注入回调获取进度\n\u003e字节大小\n#### 上传\n``` csharp\nrequestProgres((bytesSent, totalBytes) =\u003e {\n\tdouble prog = (bytesSent * 1.0) / (totalBytes * 1.0);\n\tConsole.Write(\"{0}% 上传\", Math.Round(prog * 100.0, 1).ToString(\"N1\"));\n})\n```\n#### 下载\n``` csharp\nresponseProgres((bytesSent, totalBytes) =\u003e {\n\tif (totalBytes \u003e 0)\n\t{\n\t\tdouble prog = (bytesSent * 1.0) / (totalBytes * 1.0);\n\t\tConsole.Write(\"{0}% 下载\", Math.Round(prog * 100.0, 1).ToString(\"N1\"));\n\t}\n})\n```\n\n## 请求\n### 异步错误\n``` csharp\nfail((ResultResponse result) =\u003e {\n})\n```\n### 同步获取\n``` csharp\nrequestNone();//不下载流\nrequest();//返回字符串\nrequestData();//返回字节\ndownload(\"保存目录\", \"保存文件名称（为空自动获取）\");//下载文件\n```\n\n# 实例\n\n``` csharp\nstring result = Http.Get(\"https://www.baidu.com/s\")\n.data(new { wd = \"GitHub - Haku-Men HttpLib\", params_ = \"关键字参数\" })\n.redirect()\n.request();\nConsole.Write(result);\n```\n\n# 实例下载文件\n``` csharp\nvar savapath = Http.Get(\"https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.9_240422_x64_01.exe\")\n       .redirect()\n       .responseProgres((bytesSent, totalBytes) =\u003e\n       {\n           Console.SetCursorPosition(0, 0);\n           if (totalBytes \u003e 0)\n           {\n               double prog = (bytesSent * 1.0) / (totalBytes * 1.0);\n               Console.Write(\"{0}% 下载 {1}/{2}                  \", Math.Round(prog * 100.0, 1).ToString(\"N1\"), CountSize(bytesSent), CountSize(totalBytes));\n           }\n           else\n           {\n               Console.Write(\"{0} 下载            \", CountSize(bytesSent));\n           }\n       }).download(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), \"qq.exe\");\nif (savapath != null) Console.WriteLine(\"下载成功保存至:\" + savapath);\nelse Console.WriteLine(\"下载失败\");\n```\n\n# 实例流式传输\n``` csharp\nHttp.Get(\"https://test.chatgpt.com/local_doc_chat\").request(msg =\u003e\n{\n    if (msg == null) return;\n    if (msg.StartsWith(\"data: \")) msg = msg.Substring(5).Trim();\n    System.Diagnostics.Debug.WriteLine(msg);\n});\n```\n\n# 实例获取域名IP\n``` csharp\nHttp.Get(\"https://www.baidu.com\").IP\n```\n\n# 实例全局错误捕获\n``` csharp\nConfig.fail += (HttpCore core, ResultResponse result)=\u003e\n{\n    if (result.Exception == null) return;\n    Console.Write(err.GetType());\n    Console.Write(err.Message);\n};\n```\n\n# ResultResponse介绍\n\n|代码|类型|解释|说明|\n|:--|:--|:--:|:--|\n|StatusCode|int|状态代码|`200` 为正常 常见的有`404`未找到、`302`重定向、`502`网址报错|\n|IsSuccessStatusCode|bool|响应是否成功|range `200`-`299`|\n|ServerHeader|string`?`|服务头|HTTP 200 OK BWS/1.1 Ver:1.1|\n|Uri|Uri|最终的地址||\n|Type|string`?`|服务指示类型|`Content-Type`|\n|Header|Dictionary\u003cstring, string\u003e|响应头||\n|Cookie|Dictionary\u003cstring, string\u003e|Cookie||\n|OriginalSize|long|流原始大小|动态压缩|\n|Size|long|流大小||\n|Exception|Exception`?`|异常信息||","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feva-ss%2Fhttplib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feva-ss%2Fhttplib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feva-ss%2Fhttplib/lists"}