@@ -42,6 +42,8 @@ Modification Description:v2.0.3 Modified HttpClient request timeout implementa
4242 Modification Identifier:Senparc - 20230711
4343 Modification Description:v2.2.1 Optimized Http request, timely release of resources
4444
45+ Modification Identifier:Senparc - 20241119
46+ Modification Description:v3.0.0-beta3 Add ApiClient parameter
4547----------------------------------------------------------------*/
4648
4749using System ;
@@ -106,8 +108,11 @@ private static HttpWebRequest HttpGet_Common_Net45(string url, CookieContainer c
106108 /// HttpWebRequest parameter settings for .NET Core version
107109 /// </summary>
108110 /// <returns></returns>
109- private static HttpClient HttpGet_Common_NetCore ( IServiceProvider serviceProvider , string url , CookieContainer cookieContainer = null ,
110- Encoding encoding = null , X509Certificate2 cer = null ,
111+ private static HttpClient HttpGet_Common_NetCore ( IServiceProvider serviceProvider , string url ,
112+ CookieContainer cookieContainer = null ,
113+ Encoding encoding = null ,
114+ ApiClient apiClient = null ,
115+ X509Certificate2 cer = null ,
111116 string refererUrl = null , bool useAjax = false , Dictionary < string , string > headerAddition = null , int timeOut = Config . TIME_OUT )
112117 {
113118 var handler = HttpClientHelper . GetHttpClientHandler ( cookieContainer , RequestUtility . SenparcHttpClientWebProxy , DecompressionMethods . GZip ) ;
@@ -117,7 +122,10 @@ private static HttpClient HttpGet_Common_NetCore(IServiceProvider serviceProvide
117122 handler . ClientCertificates . Add ( cer ) ;
118123 }
119124
120- HttpClient httpClient = serviceProvider . GetRequiredService < SenparcHttpClient > ( ) . Client ;
125+ var httpClient = apiClient == null
126+ ? serviceProvider . GetRequiredService < SenparcHttpClient > ( ) . Client
127+ : apiClient . SenparcHttpClient . Client ;
128+
121129 HttpClientHeader ( httpClient , refererUrl , useAjax , headerAddition , timeOut ) ;
122130
123131 return httpClient ;
@@ -169,7 +177,11 @@ public static string HttpGet(
169177 /// <returns></returns>
170178 public static string HttpGet (
171179 IServiceProvider serviceProvider ,
172- string url , CookieContainer cookieContainer = null , Encoding encoding = null , X509Certificate2 cer = null ,
180+ string url , CookieContainer cookieContainer = null , Encoding encoding = null ,
181+ #if ! NET462
182+ ApiClient apiClient = null ,
183+ #endif
184+ X509Certificate2 cer = null ,
173185 string refererUrl = null , bool useAjax = false , Dictionary < string , string > headerAddition = null , int timeOut = Config . TIME_OUT )
174186 {
175187#if NET462
@@ -192,7 +204,7 @@ public static string HttpGet(
192204 }
193205#else
194206
195- var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
207+ var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , apiClient , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
196208
197209 using ( httpClient )
198210 {
@@ -257,10 +269,14 @@ public static HttpWebResponse HttpResponseGet(string url, CookieContainer cookie
257269 /// <returns></returns>
258270 public static HttpResponseMessage HttpResponseGet (
259271 IServiceProvider serviceProvider ,
260- string url , CookieContainer cookieContainer = null , Encoding encoding = null , X509Certificate2 cer = null ,
272+ string url , CookieContainer cookieContainer = null , Encoding encoding = null ,
273+ #if ! NET462
274+ ApiClient apiClient = null ,
275+ #endif
276+ X509Certificate2 cer = null ,
261277 string refererUrl = null , bool useAjax = false , Dictionary < string , string > headerAddition = null , int timeOut = Config . TIME_OUT )
262278 {
263- var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
279+ var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , apiClient , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
264280 using ( var cts = new System . Threading . CancellationTokenSource ( timeOut ) )
265281 {
266282 try
@@ -291,7 +307,11 @@ public static HttpResponseMessage HttpResponseGet(
291307 /// <returns></returns>
292308 public static async Task < string > HttpGetAsync (
293309 IServiceProvider serviceProvider ,
294- string url , Encoding encoding = null )
310+ string url , Encoding encoding = null
311+ #if ! NET462
312+ , ApiClient apiClient = null
313+ #endif
314+ )
295315 {
296316#if NET462
297317 WebClient wc = new WebClient ( ) ;
@@ -305,7 +325,10 @@ public static async Task<string> HttpGetAsync(
305325 Proxy = SenparcHttpClientWebProxy ,
306326 } ;
307327
308- HttpClient httpClient = serviceProvider . GetRequiredService < SenparcHttpClient > ( ) . Client ;
328+ var httpClient = apiClient == null
329+ ? serviceProvider . GetRequiredService < SenparcHttpClient > ( ) . Client
330+ : apiClient . SenparcHttpClient . Client ;
331+
309332 using ( httpClient )
310333 {
311334 return await httpClient . GetStringAsync ( url ) . ConfigureAwait ( false ) ;
@@ -329,7 +352,12 @@ public static async Task<string> HttpGetAsync(
329352 /// <returns></returns>
330353 public static async Task < string > HttpGetAsync (
331354 IServiceProvider serviceProvider ,
332- string url , CookieContainer cookieContainer = null , Encoding encoding = null , X509Certificate2 cer = null ,
355+ string url , CookieContainer cookieContainer = null ,
356+ #if ! NET462
357+ ApiClient apiClient = null ,
358+ #endif
359+ Encoding encoding = null ,
360+ X509Certificate2 cer = null ,
333361 string refererUrl = null , bool useAjax = false , Dictionary < string , string > headerAddition = null , int timeOut = Config . TIME_OUT )
334362 {
335363#if NET462
@@ -351,7 +379,7 @@ public static async Task<string> HttpGetAsync(
351379 }
352380 }
353381#else
354- var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
382+ var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , apiClient , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
355383
356384 using ( httpClient )
357385 {
@@ -420,10 +448,11 @@ public static async Task<HttpWebResponse> HttpResponseGetAsync(string url, Cooki
420448 /// <returns></returns>
421449 public static async Task < HttpResponseMessage > HttpResponseGetAsync (
422450 IServiceProvider serviceProvider ,
423- string url , CookieContainer cookieContainer = null , Encoding encoding = null , X509Certificate2 cer = null ,
451+ string url , CookieContainer cookieContainer = null , Encoding encoding = null ,
452+ ApiClient apiClient = null , X509Certificate2 cer = null ,
424453 string refererUrl = null , bool useAjax = false , Dictionary < string , string > headerAddition = null , int timeOut = Config . TIME_OUT )
425454 {
426- var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
455+ var httpClient = HttpGet_Common_NetCore ( serviceProvider , url , cookieContainer , encoding , apiClient , cer , refererUrl , useAjax , headerAddition , timeOut ) ;
427456 using ( var cts = new System . Threading . CancellationTokenSource ( timeOut ) )
428457 {
429458 try
0 commit comments