Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 4a4eea8

Browse files
committed
Use CreateHttp method
1 parent 271bb28 commit 4a4eea8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Diff for: src/ServiceStack.Text/HttpUtils.WebRequest.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public static string SendStringToUrl(this string url, string method = null,
454454
string requestBody = null, string contentType = null, string accept = "*/*",
455455
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
456456
{
457-
var webReq = (HttpWebRequest)WebRequest.Create(url);
457+
var webReq = WebRequest.CreateHttp(url);
458458
return SendStringToUrl(webReq, method, requestBody, contentType, accept, requestFilter, responseFilter);
459459
}
460460

@@ -463,7 +463,7 @@ public static async Task<string> SendStringToUrlAsync(this string url, string me
463463
string contentType = null, string accept = "*/*", Action<HttpWebRequest> requestFilter = null,
464464
Action<HttpWebResponse> responseFilter = null, CancellationToken token = default)
465465
{
466-
var webReq = (HttpWebRequest)WebRequest.Create(url);
466+
var webReq = WebRequest.CreateHttp(url);
467467
return await SendStringToUrlAsync(webReq, method, requestBody, contentType, accept, requestFilter, responseFilter);
468468
}
469469

@@ -595,7 +595,7 @@ public static byte[] SendBytesToUrl(this string url, string method = null,
595595
byte[] requestBody = null, string contentType = null, string accept = "*/*",
596596
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
597597
{
598-
var webReq = (HttpWebRequest)WebRequest.Create(url);
598+
var webReq = WebRequest.CreateHttp(url);
599599
return SendBytesToUrl(webReq, method, requestBody, contentType, accept, requestFilter, responseFilter);
600600
}
601601

@@ -604,7 +604,7 @@ public static async Task<byte[]> SendBytesToUrlAsync(this string url, string met
604604
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null,
605605
CancellationToken token = default)
606606
{
607-
var webReq = (HttpWebRequest)WebRequest.Create(url);
607+
var webReq = WebRequest.CreateHttp(url);
608608
return await SendBytesToUrlAsync(webReq, method, requestBody, contentType, accept, requestFilter, responseFilter, token);
609609
}
610610

@@ -731,7 +731,7 @@ public static Stream SendStreamToUrl(this string url, string method = null,
731731
Stream requestBody = null, string contentType = null, string accept = "*/*",
732732
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
733733
{
734-
var webReq = (HttpWebRequest)WebRequest.Create(url);
734+
var webReq = WebRequest.CreateHttp(url);
735735
if (method != null)
736736
webReq.Method = method;
737737

@@ -769,7 +769,7 @@ public static async Task<Stream> SendStreamToUrlAsync(this string url, string me
769769
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null,
770770
CancellationToken token = default)
771771
{
772-
var webReq = (HttpWebRequest)WebRequest.Create(url);
772+
var webReq = WebRequest.CreateHttp(url);
773773
if (method != null)
774774
webReq.Method = method;
775775
if (contentType != null)
@@ -803,7 +803,7 @@ public static async Task<Stream> SendStreamToUrlAsync(this string url, string me
803803
{
804804
try
805805
{
806-
var webReq = (HttpWebRequest)WebRequest.Create(url);
806+
var webReq = WebRequest.CreateHttp(url);
807807
using var webRes = PclExport.Instance.GetResponse(webReq);
808808
var httpRes = webRes as HttpWebResponse;
809809
return httpRes?.StatusCode;
@@ -980,7 +980,7 @@ public static WebResponse PostFileToUrl(this string url,
980980
string accept = null,
981981
Action<HttpWebRequest> requestFilter = null)
982982
{
983-
var webReq = (HttpWebRequest)WebRequest.Create(url);
983+
var webReq = WebRequest.CreateHttp(url);
984984
using (var fileStream = uploadFileInfo.OpenRead())
985985
{
986986
var fileName = uploadFileInfo.Name;
@@ -1000,7 +1000,7 @@ public static async Task<WebResponse> PostFileToUrlAsync(this string url,
10001000
string accept = null,
10011001
Action<HttpWebRequest> requestFilter = null, CancellationToken token = default)
10021002
{
1003-
var webReq = (HttpWebRequest)WebRequest.Create(url);
1003+
var webReq = WebRequest.CreateHttp(url);
10041004
using (var fileStream = uploadFileInfo.OpenRead())
10051005
{
10061006
var fileName = uploadFileInfo.Name;
@@ -1020,7 +1020,7 @@ public static WebResponse PutFileToUrl(this string url,
10201020
string accept = null,
10211021
Action<HttpWebRequest> requestFilter = null)
10221022
{
1023-
var webReq = (HttpWebRequest)WebRequest.Create(url);
1023+
var webReq = WebRequest.CreateHttp(url);
10241024
using (var fileStream = uploadFileInfo.OpenRead())
10251025
{
10261026
var fileName = uploadFileInfo.Name;
@@ -1040,7 +1040,7 @@ public static async Task<WebResponse> PutFileToUrlAsync(this string url,
10401040
string accept = null,
10411041
Action<HttpWebRequest> requestFilter = null, CancellationToken token = default)
10421042
{
1043-
var webReq = (HttpWebRequest)WebRequest.Create(url);
1043+
var webReq = WebRequest.CreateHttp(url);
10441044
using (var fileStream = uploadFileInfo.OpenRead())
10451045
{
10461046
var fileName = uploadFileInfo.Name;

0 commit comments

Comments
 (0)