@@ -455,6 +455,21 @@ public static string SendStringToUrl(this string url, string method = null,
455
455
Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null )
456
456
{
457
457
var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
458
+ return SendStringToUrl ( webReq , method , requestBody , contentType , accept , requestFilter , responseFilter ) ;
459
+ }
460
+
461
+ public static async Task < string > SendStringToUrlAsync ( this string url , string method = null ,
462
+ string requestBody = null ,
463
+ string contentType = null , string accept = "*/*" , Action < HttpWebRequest > requestFilter = null ,
464
+ Action < HttpWebResponse > responseFilter = null , CancellationToken token = default )
465
+ {
466
+ var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
467
+ return await SendStringToUrlAsync ( webReq , method , requestBody , contentType , accept , requestFilter , responseFilter ) ;
468
+ }
469
+
470
+ public static string SendStringToUrl ( this HttpWebRequest webReq , string method , string requestBody , string contentType ,
471
+ string accept , Action < HttpWebRequest > requestFilter , Action < HttpWebResponse > responseFilter )
472
+ {
458
473
if ( method != null )
459
474
webReq . Method = method ;
460
475
if ( contentType != null )
@@ -486,13 +501,11 @@ public static string SendStringToUrl(this string url, string method = null,
486
501
responseFilter ? . Invoke ( ( HttpWebResponse ) webRes ) ;
487
502
return stream . ReadToEnd ( UseEncoding ) ;
488
503
}
489
-
490
- public static async Task < string > SendStringToUrlAsync ( this string url , string method = null ,
491
- string requestBody = null ,
492
- string contentType = null , string accept = "*/*" , Action < HttpWebRequest > requestFilter = null ,
493
- Action < HttpWebResponse > responseFilter = null , CancellationToken token = default )
504
+
505
+ public static async Task < string > SendStringToUrlAsync ( this HttpWebRequest webReq ,
506
+ string method , string requestBody , string contentType , string accept ,
507
+ Action < HttpWebRequest > requestFilter , Action < HttpWebResponse > responseFilter )
494
508
{
495
- var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
496
509
if ( method != null )
497
510
webReq . Method = method ;
498
511
if ( contentType != null )
@@ -583,6 +596,21 @@ public static byte[] SendBytesToUrl(this string url, string method = null,
583
596
Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null )
584
597
{
585
598
var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
599
+ return SendBytesToUrl ( webReq , method , requestBody , contentType , accept , requestFilter , responseFilter ) ;
600
+ }
601
+
602
+ public static async Task < byte [ ] > SendBytesToUrlAsync ( this string url , string method = null ,
603
+ byte [ ] requestBody = null , string contentType = null , string accept = "*/*" ,
604
+ Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null ,
605
+ CancellationToken token = default )
606
+ {
607
+ var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
608
+ return await SendBytesToUrlAsync ( webReq , method , requestBody , contentType , accept , requestFilter , responseFilter , token ) ;
609
+ }
610
+
611
+ public static byte [ ] SendBytesToUrl ( this HttpWebRequest webReq , string method , byte [ ] requestBody , string contentType ,
612
+ string accept , Action < HttpWebRequest > requestFilter , Action < HttpWebResponse > responseFilter )
613
+ {
586
614
if ( method != null )
587
615
webReq . Method = method ;
588
616
@@ -611,13 +639,10 @@ public static byte[] SendBytesToUrl(this string url, string method = null,
611
639
using var stream = webRes . GetResponseStream ( ) ;
612
640
return stream . ReadFully ( ) ;
613
641
}
614
-
615
- public static async Task < byte [ ] > SendBytesToUrlAsync ( this string url , string method = null ,
616
- byte [ ] requestBody = null , string contentType = null , string accept = "*/*" ,
617
- Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null ,
618
- CancellationToken token = default )
642
+
643
+ public static async Task < byte [ ] > SendBytesToUrlAsync ( this HttpWebRequest webReq , string method , byte [ ] requestBody ,
644
+ string contentType , string accept , Action < HttpWebRequest > requestFilter , Action < HttpWebResponse > responseFilter , CancellationToken token )
619
645
{
620
- var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
621
646
if ( method != null )
622
647
webReq . Method = method ;
623
648
if ( contentType != null )
@@ -646,7 +671,7 @@ public static async Task<byte[]> SendBytesToUrlAsync(this string url, string met
646
671
using var stream = webRes . GetResponseStream ( ) ;
647
672
return await stream . ReadFullyAsync ( token ) . ConfigAwait ( ) ;
648
673
}
649
-
674
+
650
675
public static Stream GetStreamFromUrl ( this string url , string accept = "*/*" ,
651
676
Action < HttpWebRequest > requestFilter = null , Action < HttpWebResponse > responseFilter = null )
652
677
{
@@ -779,11 +804,9 @@ public static async Task<Stream> SendStreamToUrlAsync(this string url, string me
779
804
try
780
805
{
781
806
var webReq = ( HttpWebRequest ) WebRequest . Create ( url ) ;
782
- using ( var webRes = PclExport . Instance . GetResponse ( webReq ) )
783
- {
784
- var httpRes = webRes as HttpWebResponse ;
785
- return httpRes ? . StatusCode ;
786
- }
807
+ using var webRes = PclExport . Instance . GetResponse ( webReq ) ;
808
+ var httpRes = webRes as HttpWebResponse ;
809
+ return httpRes ? . StatusCode ;
787
810
}
788
811
catch ( Exception ex )
789
812
{
0 commit comments