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

    类 HttpClient

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

    方法

    • 早期执行

      参数

      • reason: string

        提供给请求对应的 Promise 的 reject 原因。

      返回 void

      取消所有尚未完成的请求。

      Cancels all pending requests.

    • 早期执行

      参数

      • uri: string

        请求的 URL。

        URL to make an HTTP Request to.

      返回 Promise<HttpResponse>

      解析到对应响应的 Promise。

      An awaitable promise that contains the HTTP response.

      发起一个 HTTP GET 请求。

      Performs a simple HTTP get request.

    • 早期执行

      参数

      • config: HttpRequest

        用于发起请求的配置对象。

        Contains an HTTP Request object with configuration data on the HTTP request.

      返回 Promise<HttpResponse>

      解析到对应响应的 Promise。

      An awaitable promise that contains the HTTP response.

      发起一个 HTTP 请求。 Performs an HTTP 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);
      }