@@ -120,6 +120,10 @@ bool HTTPClient::begin(String url, const char* CAcert)
120
120
*/
121
121
bool HTTPClient::begin (String url)
122
122
{
123
+
124
+ if (beginInternal (url, " https" )) {
125
+ return begin (url, (const char *)NULL );
126
+ }
123
127
_transportTraits.reset (nullptr );
124
128
_port = 80 ;
125
129
if (!beginInternal (url, " http" )) {
@@ -143,6 +147,11 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
143
147
}
144
148
145
149
_protocol = url.substring (0 , index );
150
+ if (_protocol != expectedProtocol) {
151
+ log_d (" [HTTP-Client][begin] unexpected protocol: %s, expected %s" , _protocol.c_str (), expectedProtocol);
152
+ return false ;
153
+ }
154
+
146
155
url.remove (0 , (index + 3 )); // remove http:// or https://
147
156
148
157
index = url.indexOf (' /' );
@@ -168,10 +177,6 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
168
177
_host = host;
169
178
}
170
179
_uri = url;
171
- if (_protocol != expectedProtocol) {
172
- log_d (" [HTTP-Client][begin] unexpected protocol: %s, expected %s" , _protocol.c_str (), expectedProtocol);
173
- return false ;
174
- }
175
180
log_d (" [HTTP-Client][begin] host: %s port: %d url: %s" , _host.c_str (), _port, _uri.c_str ());
176
181
return true ;
177
182
}
0 commit comments