{"id":16686772,"url":"https://github.com/kklldog/agilehttp","last_synced_at":"2025-07-24T14:38:56.506Z","repository":{"id":52240255,"uuid":"230421306","full_name":"kklldog/AgileHttp","owner":"kklldog","description":"An aglie http client .","archived":false,"fork":false,"pushed_at":"2023-03-24T15:37:08.000Z","size":57,"stargazers_count":56,"open_issues_count":0,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-21T04:38:52.370Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kklldog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-12-27T10:11:45.000Z","updated_at":"2025-02-12T06:38:46.000Z","dependencies_parsed_at":"2023-01-25T12:46:04.753Z","dependency_job_id":"cb729be7-0000-49f2-9289-921373be49b3","html_url":"https://github.com/kklldog/AgileHttp","commit_stats":{"total_commits":27,"total_committers":3,"mean_commits":9.0,"dds":"0.18518518518518523","last_synced_commit":"c134c6ce66311964b1b9cd707545a0e0908cc3e6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kklldog/AgileHttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklldog%2FAgileHttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklldog%2FAgileHttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklldog%2FAgileHttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklldog%2FAgileHttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kklldog","download_url":"https://codeload.github.com/kklldog/AgileHttp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklldog%2FAgileHttp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266856934,"owners_count":23995767,"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-07-24T02:00:09.469Z","response_time":99,"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":[],"created_at":"2024-10-12T15:06:47.559Z","updated_at":"2025-07-24T14:38:56.445Z","avatar_url":"https://github.com/kklldog.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AgileHttp\nAn aglie http client .    \n![Nuget](https://img.shields.io/nuget/v/AgileHttp?color=green) ![Nuget](https://img.shields.io/nuget/dt/Agilehttp?color=green)\n## 依赖 \nNewtonsoft.Json 12.0.3 \n## 安装 \nInstall-Package AgileHttp \n## 示例 \n### 使用HTTP.Send方法 \n使用HTTP.Send / HTTP.SendAsync方法可以直接发送一个请求   \n```\nHTTP.Send(\"http://www.baidu.com\") // 默认为Get方法 \nHTTP.Send(\"http://www.baidu.com\", \"POST\")  \nHTTP.Send(\"http://www.baidu.com\", \"POST\", new { name = \"mjzhou\" })  \nHTTP.Send(\"http://www.baidu.com\", \"POST\", new { name = \"mjzhou\" }, new RequestOptions { ContentType = \"application/json\" }) \n\nResponseInfo response = HTTP.Send(\"http://localhost:5000/api/user/1\");\nstring content = response.GetResponseContent(); //获取http响应返回值的文本内容\n```\nHTTP.SendAsync方法是HTTP.Send方法的异步版本   \n### 使用HttpClient类    \n如果不喜欢手写\"GET\",\"POST\",\"PUT\"等HTTP方法，可以是使用HttpClient类。HttpClient类内置了GET,POST,PUT,DELETE,OPTIONS几个常用的方法。   \n```\nvar client = new HttpClient(\"http://www.baidu.com\");\nclient.Get();//使用HttpClient发送Get请求\n\nvar client = new HttpClient(\"http://www.baidu.com\");\nclient.Config(new RequestOptions { ContentType = \"application/json\" });\nclient.Post(new { name = \"mjzhou\" }); //使用HttpClient发送Post请求\n\nResponseInfo response = new HttpClient(\"http://localhost:5000/api/user/1\").Get();\nstring content = response.GetResponseContent(); //获取http响应返回值的文本内容\nUser user1 = new HttpClient(\"http://localhost:5000/api/user/1\").Get\u003cUser\u003e(); //泛型方法可以直接反序列化成对象。\n```\nGet,Post等方法都有异步版本GetAsync,PostAsync\n### 使用扩展方法   \nC#强大的扩展方法可以让写代码行云流水。AgileHttp提供了几个扩展方法，让使用更人性化。   \n```\nvar result = \"http://localhost:5000/api/user\"\n    .AppendQueryString(\"name\", \"kklldog\")\n    .AsHttpClient()\n    .Get()\n    .GetResponseContent();\n\nvar user = \"http://localhost:5000/api/user\"\n    .AppendQueryString(\"name\", \"kklldog\")\n    .AsHttpClient()\n    .Get\u003cUser\u003e();\n```\n1. String.AppendQueryString   \n给一个字符串添加查询参数\n```\n\"http://localhost:5000/api/user\".AppendQueryString(\"name\", \"mjzhou\") // 返回结果为\"http://localhost:5000/api/user?name=mjzhou\"\n```\n2. String.AppendQueryStrings   \n给一个字符串添加多个查询参数\n```\nvar qs = new Dictionary\u003cstring, object\u003e();\nqs.Add(\"a\", \"1\");\nqs.Add(\"b\", \"2\");\n\"http://localhost:5000/api/user\".AppendQueryStrings(qs) // 返回结果为\"http://localhost:5000/api/user?a=1\u0026b=2\"\n```\n3. String.AsHttp   \n以当前字符串为URL创建一个HttpRequest\n```\n\"http://www.baidu.com\".AsHttp().Send(); //默认为Get\n\"http://localhost:5000/api/user\".AsHttp(\"POST\", new { name = \"mjzhou\" }).Send();\n```\n4. String.AsHttpClient   \n以当前字符串为URL创建一个HttpClient\n```\n\"http://www.baidu.com\".AsHttpClient().Get();\n\"http://localhost:5000/api/user\".AsHttpClient().Post(new { name = \"mjzhou\" });\n```\n5. ResponseInfo.Deserialize T    \nResponseInfo是请求结果的包装类，使用Deserialize方法可以直接反序列化成对象。如果没有配置RequestOptions则使用默认SerializeProvider。\n```\nHTTP.Send(\"http://www.baidu.com\").Deserialize\u003cUser\u003e();\n```\n### RequestOptions    \n使用RequestOptions可以对每个请求进行配置，比如设置ContentType，设置Headers，设置代理等等。   \n\n| 属性 | 说明 |   \n| ---- | ---- |   \n| SerializeProvider | 获取序列化器 |   \n| Encoding | 获取编码方式 |\n| Headers | 获取或设置HttpHeaders |\n| ContentType | 获取或设置Http ContentType属性 |\n| Host | 获取或设置Http Host属性 |\n| Connection | 获取或设置Http Connection属性 |\n| UserAgent | 获取或设置Http UserAgent属性 | \n| Accept | 获取或设置Http Accept属性 |\n| Referer | 获取或设置Http Referer属性 |\n| Certificate | 获取或设置X509证书信息 |\n| Proxy | 获取或设置代理信息 |\n### 关于序列化/反序列化   \n当你使用Post，Put（不限于这2个方法）方法提交一个对象的时候AgileHttp会自动就行序列化。使用泛型Get T, Post T方法会自动进行反序列化。默认使用JsonSerializeProvider来进行序列化及反序列化。JsonSerializeProvider使用著名的Newtonsoft.Json实现了ISerializeProvider接口，如果你喜欢你也可以自己实现自己的Provider，比如实现一个XMLSerializeProvider。\n```\n public interface ISerializeProvider\n  {\n      T Deserialize\u003cT\u003e(string content);\n      string Serialize(object obj);\n  }\n```\nAgileHttp提供2个地方来修改SerializeProvider：   \n1. 通过RequestOptions为单个Http请求配置序列化器\n```\nvar xmlSerializeProvider = new xmlSerializeProvider();\nvar client = new HttpClient(\"http://www.baidu.com\");\nclient.Config(new RequestOptions(xmlSerializeProvider));\n```\n2. 通过HTTP.SetDefaultSerializeProvider(ISerializeProvider provider)更改全局默认序列化器\n```\nvar xmlSerializeProvider = new xmlSerializeProvider();\nHTTP.SetDefaultSerializeProvider(xmlSerializeProvider);\n```\n注意！：如果提交的body参数的类型为String或者byte[]不会进行再次序列化。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklldog%2Fagilehttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkklldog%2Fagilehttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklldog%2Fagilehttp/lists"}