std::net::http::http_clientHTTP client for making outbound requests.
Provides functions for performing HTTP GET and POST requests and reading the response.
import std::net::http;
fn main() {
let body = http_client.get_string("https://example.com");
println(body);
let resp = http_client.get("https://api.example.com/data");
println(resp.status());
println(resp.content_type());
resp.free();
}
getPerform an HTTP GET request and return a Response handle.
let resp = http_client.get("https://example.com");
println(resp.status());
resp.free();
postPerform an HTTP POST request and return a Response handle.
let resp = http_client.post("https://api.example.com/data", "application/json", "{}");
resp.free();
get_stringPerform an HTTP GET request and return the response body as a string.
This is a convenience function that combines the request and body extraction in a single call.
let body = http_client.get_string("https://example.com");
println(body);
post_stringPerform an HTTP POST request and return the response body as a string.
Returns an empty string on network error.
let body = http_client.post_string(
"https://api.example.com/submit",
"application/json",
"{\"key\": \"value\"}",
);
println(body);
ResponseAn opaque HTTP response handle.
Obtained from http_client.get(url) or http_client.post(...).
Must be freed with free() when no longer needed.
ResponseMethodsMethods available on an HTTP Response.