For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server-net/classes/HttpHeader.md.

Class: HttpHeader

network

Beta

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

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

Example

simpleHttpRequest.ts

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

Constructor

new HttpHeader(key, value): HttpHeader

Beta

Parameters

key

string

value

any

Returns

HttpHeader

Properties

key

key: string

Early Execution Beta

Remarks

请求标头的键。

Key of the HTTP header.


value

value: any

Early Execution Beta

Remarks

请求标头的值。

Value of the HTTP header.

同领域相关