httpRequest

suspend fun httpRequest(url: String, method: String = "GET", headers: Map<String, String> = emptyMap(), timeout: Int = 0, content: String? = null, contentStream: Pair<InputStream, Long>? = null, followRedirects: Boolean = true, includeCredentials: Boolean = false, onCancel: (Net.HttpRequest) -> Unit? = null): HttpRequestResult

Executes a HTTP request asynchronously.

Return

HttpRequestResult storing HTTP response data.

Parameters

url

URL that will be queried.

method

HTTP method. GET by default. See com.badlogic.gdx.Net.HttpMethods.

headers

HTTP request headers mapped to their values. Empty by default.

timeout

time before the request is cancelled. If the request was cancelled, an exception will be thrown (type of exception might vary on each platform).

content

body of the request.

contentStream

body of the request. Alternative to content. Pair of an InputStream along with its size.

followRedirects

whether 301 and 302 redirects are followed. Defaults to true.

includeCredentials

whether a cross-origin request will include credentials. Relevant only on web platforms.

onCancel

executed when the HTTP request is cancelled through coroutine cancellation. Optional, should be passed only if coroutine's Job.cancel can be called.

See also

Net.HttpRequest