类 HttpHeader实验性

表示一个请求标头,即包含了请求元数据的键值对。

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

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);
}

构造函数

属性

构造函数

属性

key: string

请求标头的键。

Key of the HTTP header.

无法在只读模式下修改此属性,详见 WorldBeforeEvents

value: string | SecretString

请求标头的值。

Value of the HTTP header.

无法在只读模式下修改此属性,详见 WorldBeforeEvents