HTTP/1.1-Client für GET- und POST-Anfragen ohne TLS. Baut auf std.net.socket und std.net.dns auf und übernimmt Verbindungsaufbau, Header-Generierung, Body-Übergabe und Response-Parsing. Antworten enthalten Statuscode, Header-Anzahl, Content-Length und Body.
Geeignet für REST-API-Aufrufe in internen Netzwerken, Webhook-Versand, einfache Webseiten-Abfragen und alle HTTP-Kommunikation ohne Verschlüsselung. Für HTTPS-Verbindungen std.net.https verwenden.
import std.net.http;
var resp: HTTPResponse := HTTPGet("api.example.com", "/v1/status");
if (resp.statusCode == HTTP_OK) {
PrintStr("OK\n");
}
HTTPResponseFree(resp);
std.net.socketstd.net.dnsstd.net.types| Name | Typ | Wert | Sichtbarkeit |
|---|---|---|---|
HTTP_PORT | int64 | 80 | pub |
HTTPS_PORT | int64 | 443 | pub |
HTTP_GET | int64 | 1 | pub |
HTTP_POST | int64 | 2 | pub |
HTTP_PUT | int64 | 3 | pub |
HTTP_DELETE | int64 | 4 | pub |
HTTP_OK | int64 | 200 | pub |
HTTP_CREATED | int64 | 201 | pub |
HTTP_NO_CONTENT | int64 | 204 | pub |
HTTP_BAD_REQUEST | int64 | 400 | pub |
HTTP_UNAUTHORIZED | int64 | 401 | pub |
HTTP_FORBIDDEN | int64 | 403 | pub |
HTTP_NOT_FOUND | int64 | 404 | pub |
HTTP_SERVER_ERROR | int64 | 500 | pub |
| Feld | Typ |
|---|---|
statusCode | int64 |
headerCount | int64 |
contentLength | int64 |
bodySize | int64 |
| Feld | Typ |
|---|---|
port | int64 |
bodySize | int64 |
| Signatur | Sichtbarkeit | Beschreibung |
|---|---|---|
HTTPRequestBuild(req: HTTPRequest): int64 | pub | HTTP-Anfrage-Puffer aus Struct aufbauen |
HTTPSend(request: HTTPRequest): HTTPResponse | pub | HTTP-Anfrage senden und Antwort empfangen |
HTTPResponseFree(response: HTTPResponse) | pub | Speicher einer HTTP-Antwort freigeben |
HTTPGet(host: int64, path: int64): HTTPResponse | pub | HTTP-GET-Anfrage an Host senden |
HTTPPost(host: int64, path: int64, body: int64, bodySize: int64): HTTPResponse | pub | HTTP-POST-Anfrage mit Body senden |