Show / Hide Table of Contents

Method ExtInternet.Get(+ 1 overload)


Overload

Sends a GET request to the specified URL, and gets the response.

public static HttpResponseMessage Get(this HttpClient t, string url, bool dontWait = false, IEnumerable<string> headers = null, string auth = null, Action<HttpRequestMessage> also = null)
Parameters
t  (HttpClient)
url  (string)

URL. To create URL with urlencoded parameters you can use internet.urlAppend.

dontWait  (bool)

Use System.Net.Http.HttpCompletionOption.ResponseHeadersRead.

headers  (IEnumerable<string>)

null or request headers like ["name1: value1", "name2: value2"]. Also you can add headers to System.Net.Http.HttpClient.DefaultRequestHeaders, like internet.http.DefaultRequestHeaders.Add("User-Agent", "Script/1.0");.

auth  (string)

String like "username:password" for basic authentication. Adds Authorization header.

also  (Action<HttpRequestMessage>)

Can set more properties for the request.

Returns
HttpResponseMessage

An HttpResponseMessage object that can be used to get response content (web page HTML, JSON, file, etc), headers etc. To get content use ExtInternet.Text etc.

Exceptions
Exception

Exceptions of System.Net.Http.HttpClient.Send. If headers used, exceptions of ExtInternet.AddMany.

UriFormatException

Invalid URL format.

Examples

string s = internet.http.Get("https://httpbin.org/anything").Text();

Overload(top)

Sends a GET request to the specified URL, and gets the response. Saves the response content (file, web page, etc) in a file.

public static HttpResponseMessage Get(this HttpClient t, string url, string resultFile, IEnumerable<string> headers = null, string auth = null, Action<HttpRequestMessage> also = null)
Parameters
t  (HttpClient)
url  (string)

URL. To create URL with urlencoded parameters you can use internet.urlAppend.

resultFile  (string)

File path. The function uses pathname.normalize. Creates parent directory if need.

headers  (IEnumerable<string>)

null or request headers like ["name1: value1", "name2: value2"]. Also you can add headers to System.Net.Http.HttpClient.DefaultRequestHeaders, like internet.http.DefaultRequestHeaders.Add("User-Agent", "Script/1.0");.

auth  (string)

String like "username:password" for basic authentication. Adds Authorization header.

also  (Action<HttpRequestMessage>)

Can set more properties for the request.

Returns
HttpResponseMessage

An HttpResponseMessage object that contains response headers etc. Rarely used.

Exceptions
Exception

Exceptions of System.Net.Http.HttpClient.Send and ExtInternet.Save. If headers used, exceptions of ExtInternet.AddMany.