Method ExtInternet.TryGet
Overload
Sends a GET request to the specified URL, and gets the response. Handles HTTP errors and exceptions.
public static bool TryGet(this HttpClient t, out HttpResponseMessage r, string url, bool dontWait = false, IEnumerable<string> headers = null, bool printError = false, string auth = null, Action<HttpRequestMessage> also = null)
Parameters
t (HttpClient) |
r (HttpResponseMessage)
Receives HttpResponseMessage object that can be used to get response content (web page HTML, JSON, file, etc), headers etc. See example. Will be |
url (string)
URL. To create URL with urlencoded parameters you can use internet.urlAppend. |
dontWait (bool) |
headers (IEnumerable<string>)
|
printError (bool)
If failed, call print.warning. |
auth (string)
String like |
also (Action<HttpRequestMessage>)
Can set more properties for the request. |
Returns
bool
|
Exceptions
UriFormatException
Invalid URL format. |
Exception
If headers used, exceptions of ExtInternet.AddMany. |
Examples
if (!internet.http.TryGet(out var r, "https://httpbin.org/anything", printError: true)) return;
print.it(r.Text());