@minecraft
    正在准备搜索索引...

    类 HttpRequest

    包含构成 HTTP 请求所需的参数。主要用于发起请求。

    Main object for structuring 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);
    }
    索引

    构造函数

    属性

    body: string

    请求的携带的主体负载内容。

    Content of the body of the HTTP request.

    headers: HttpHeader[]

    该请求的请求标头集合。

    A collection of HTTP headers to add to the outbound request.

    该请求的请求方法(例如 GET、PUT 或 PATCH)。

    HTTP method (e.g., GET or PUT or PATCH) to use for making the request.

    timeout: number

    在请求被视为超时而取消前的最大时长,单位为秒。

    Amount of time, in seconds, before the request times out and is abandoned.

    uri: string

    请求访问的资源 URI。

    The HTTP resource to access.

    方法