早期执行
请求的 URL。
URL to make an HTTP Request to.
解析到对应响应的 Promise。
An awaitable promise that contains the HTTP response.
早期执行
用于发起请求的配置对象。
Contains an HTTP Request object with configuration data on the HTTP request.
解析到对应响应的 Promise。
An awaitable promise that contains the HTTP response.
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);
}
示例: simpleHttpRequest.ts