diff --git a/Docs/1.3.0.基础使用.管理客户端.ipynb b/Docs/1.3.0.基础使用.管理客户端.ipynb index 58fca0f..62421e2 100644 --- a/Docs/1.3.0.基础使用.管理客户端.ipynb +++ b/Docs/1.3.0.基础使用.管理客户端.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -37,7 +37,40 @@ "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "启动WebApi项目\r\n" + ] + }, + { + "data": { + "text/plain": [ + "e:\\王高峰\\我的项目\\学习项目\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.exe" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "程序[e:\\王高峰\\我的项目\\学习项目\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.exe]已在新的命令行窗口执行。如果未出现新命令行窗口,可能是程序错误造成窗口闪现!\r\n" + ] + } + ], "source": [ "//全局设置,行运行一次,为后续准备\n", "#r \"nuget:System.Net.Http.Json\"\n", @@ -161,6 +194,12 @@ "cell_type": "code", "execution_count": null, "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, "vscode": { "languageId": "polyglot-notebook" } @@ -224,6 +263,12 @@ "cell_type": "code", "execution_count": null, "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, "vscode": { "languageId": "polyglot-notebook" } @@ -303,6 +348,12 @@ "cell_type": "code", "execution_count": null, "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, "vscode": { "languageId": "polyglot-notebook" } @@ -400,6 +451,120 @@ " 2. 工具类方法比较多且和业务直接相关,需要手动维护\n" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9193\r\n" + ] + } + ], + "source": [ + "// 百度服务类\n", + "public sealed class BaiduService \n", + "{\n", + " private readonly HttpClient _httpClient;\n", + " public BaiduService()\n", + " {\n", + " //初始化httpClient\n", + " var baseHander = new SocketsHttpHandler() \n", + " { \n", + " MaxConnectionsPerServer = 1000 \n", + " };\n", + "\n", + " _httpClient = new HttpClient(baseHander)\n", + " {\n", + " Timeout = TimeSpan.FromSeconds(10),\n", + " BaseAddress = new Uri(\"http://www.baidu.com\"),\n", + " };\n", + " }\n", + "\n", + " ///// \n", + " /// 获取百度首页长度\n", + " /// \n", + " public async Task GetIndexLengthAsync(string url)\n", + " {\n", + " var response = await _httpClient.GetAsync(url);\n", + " response.EnsureSuccessStatusCode();\n", + " var result = await response.Content.ReadAsStringAsync();\n", + " return result.Length;\n", + " }\n", + "}\n", + "//调用示例\n", + "{\n", + " var service = new BaiduService();\n", + " var result = await service.GetIndexLengthAsync(\"/\");\n", + " Console.WriteLine(result);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "配置文件根目录:e:\\王高峰\\我的项目\\学习项目\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Core\n", + "{\"data\":\"操作成功\",\"code\":1,\"message\":\"成功\"}\n" + ] + } + ], + "source": [ + "// 本机服务类\n", + "// 百度服务类\n", + "public sealed class LocalService \n", + "{\n", + " private readonly HttpClient _httpClient;\n", + " public LocalService()\n", + " {\n", + " //初始化httpClient\n", + " var baseHander = new SocketsHttpHandler() \n", + " { \n", + " MaxConnectionsPerServer = 1000 \n", + " };\n", + "\n", + " _httpClient = new HttpClient(baseHander)\n", + " {\n", + " Timeout = TimeSpan.FromSeconds(10),\n", + " BaseAddress = new Uri(WebApiConfigManager.GetWebApiConfig().BaseUrl),\n", + " };\n", + " }\n", + "\n", + " ///// \n", + " /// 获取百度首页长度\n", + " /// \n", + " public async Task GetIndexAsync(string url)\n", + " {\n", + " var response = await _httpClient.GetAsync(url);\n", + " response.EnsureSuccessStatusCode();\n", + " var result = await response.Content.ReadAsStringAsync();\n", + " return result;\n", + " }\n", + "}\n", + "//调用示例\n", + "{\n", + " var service2 = new LocalService();\n", + " var result = await service2.GetIndexAsync(\"/api/Simple/GetAccount\");\n", + " Console.WriteLine(result);\n", + "}" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/Docs/1.4.8.高级使用.线程限流.ipynb b/Docs/1.4.8.高级使用.线程限流.ipynb new file mode 100644 index 0000000..72e34d0 --- /dev/null +++ b/Docs/1.4.8.高级使用.线程限流.ipynb @@ -0,0 +1,70 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "source": [ + "# HttpClient 限流(System.Threading.RateLimiting)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "source": [ + "## 1、System.Threading.RateLimiting 概述" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2、结合HttpClient 实现限流" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "python" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": "csharp" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}