跳到主要内容

Class: HttpHeader

Represents an HTTP header - a key/value pair of meta-information about a request.

Example

import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';

async function updateScore() {
const req = new HttpRequest('http://localhost:3000/updateScore');

req.body = JSON.stringify({
score: 22,
});

req.method = HttpRequestMethod.Post;
req.headers = [
new HttpHeader('Content-Type', 'application/json'),
new HttpHeader('auth', 'my-auth-token'),
];

await http.request(req);
}

Constructors

new HttpHeader()

new HttpHeader(key, value): HttpHeader

Parameters

ParameterType
keystring
valuestring | SecretString

Returns

HttpHeader

Properties

key

key: string

Remarks

Key of the HTTP header.

This property can't be edited in read-only mode.


value

value: string | SecretString

Remarks

Value of the HTTP header.

This property can't be edited in read-only mode.