@@ -814,15 +814,23 @@ void InferContentType(string contentType, HttpRequestMessage req)
814814 }
815815 }
816816
817- void setHttpVersion ( HttpRequestMessage req )
817+ void SetHttpVersion ( HttpRequestMessage req )
818818 {
819819 string httpVersion ;
820820 if ( Config . GetValueOf ( "HttpClientHttpVersion" , out httpVersion ) )
821821 {
822822 if ( httpVersion == "1.0" )
823823 req . Version = HttpVersion . Version10 ;
824+ #if NETCORE
825+ else if ( httpVersion = = "2.0" )
826+ req . Version = HttpVersion . Version20 ;
827+ else if ( httpVersion = = "3.0" )
828+ req . Version = HttpVersion . Version30 ;
829+ #endif
824830 else
825831 req . Version = HttpVersion . Version11 ;
832+
833+ GXLogging . Debug ( log , "Setting HTTPClient request version to " , req . Version . ToString ( ) ) ;
826834 }
827835 else
828836 req . Version = HttpVersion . Version11 ;
@@ -845,7 +853,7 @@ HttpResponseMessage ExecuteRequest(string method, string requestUrl, bool contex
845853 Method = new HttpMethod ( method ) ,
846854 } ;
847855 setHeaders ( request , cookies , out string contentType ) ;
848- setHttpVersion ( request ) ;
856+ SetHttpVersion ( request ) ;
849857 bool disposableInstance = true ;
850858 try
851859 {
@@ -873,7 +881,7 @@ HttpResponseMessage ExecuteRequest(string method, string requestUrl, bool contex
873881 request . Content = new ByteArrayContent ( reqStream . ToArray ( ) ) ;
874882 setContentHeaders ( request , contentType ) ;
875883#if NETCORE
876- response = client . Send ( request , HttpCompletionOption . ResponseHeadersRead ) ;
884+ response = client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead ) . GetAwaiter ( ) . GetResult ( ) ;
877885 response . ExtractCookies ( cookies ) ;
878886#else
879887 response = client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -907,7 +915,7 @@ async Task<HttpResponseMessage> ExecuteRequestAsync(string method, string reques
907915 Method = new HttpMethod ( method ) ,
908916 } ;
909917 setHeaders ( request , cookies , out string contentType ) ;
910- setHttpVersion ( request ) ;
918+ SetHttpVersion ( request ) ;
911919 bool disposableInstance = true ;
912920 try
913921 {
@@ -1361,14 +1369,20 @@ static WebProxy getProxy(string proxyHost, int proxyPort, ArrayList authenticati
13611369 return null ;
13621370 }
13631371
1364- private void setHttpVersion ( HttpWebRequest req )
1372+ private void SetHttpVersion ( HttpWebRequest req )
13651373 {
13661374
13671375 string httpVersion ;
13681376 if ( Config . GetValueOf ( "HttpClientHttpVersion" , out httpVersion ) )
13691377 {
13701378 if ( httpVersion == "1.0" )
13711379 req . ProtocolVersion = HttpVersion . Version10 ;
1380+ #if NETCORE
1381+ else if ( httpVersion = = "2.0" )
1382+ req . ProtocolVersion = HttpVersion . Version20 ;
1383+ else if ( httpVersion = = "3.0" )
1384+ req . ProtocolVersion = HttpVersion . Version30 ;
1385+ #endif
13721386 else
13731387 req . ProtocolVersion = HttpVersion . Version11 ;
13741388 }
@@ -1430,7 +1444,7 @@ async Task<HttpWebRequest> buildRequestAsync(string method, string requestUrl, C
14301444 req . ClientCertificates . Add ( cert ) ;
14311445 req . Method = method . Trim ( ) ;
14321446 req . Timeout = _timeout ;
1433- setHttpVersion ( req ) ;
1447+ SetHttpVersion ( req ) ;
14341448 WebProxy proxy = getProxy ( _proxyHost , _proxyPort , _authProxyCollection ) ;
14351449 if ( proxy != null )
14361450 req . Proxy = proxy ;
@@ -1482,7 +1496,7 @@ HttpWebRequest buildRequest(string method, string requestUrl, CookieContainer co
14821496 req . ClientCertificates . Add ( cert ) ;
14831497 req . Method = method . Trim ( ) ;
14841498 req . Timeout = _timeout ;
1485- setHttpVersion ( req ) ;
1499+ SetHttpVersion ( req ) ;
14861500 WebProxy proxy = getProxy ( _proxyHost , _proxyPort , _authProxyCollection ) ;
14871501 if ( proxy != null )
14881502 req . Proxy = proxy ;
0 commit comments