HttpClient Class
Examples
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);
}
Methods
cancelAll
cancelAll(reason: string): void
Cancels all pending requests.
Parameters
- reason: string
Important
This function can't be called in read-only mode.
get
"get"(uri: string): Promise<HttpResponse>
Performs a simple HTTP get request.
Parameters
uri: string
URL to make an HTTP Request to.
Returns Promise<HttpResponse> - An awaitable promise that contains the HTTP response.
Important
This function can't be called in read-only mode.
request
request(config: HttpRequest): Promise<HttpResponse>
Performs an HTTP request.
Parameters
config: HttpRequest
Contains an HTTP Request object with configuration data on the HTTP request.
Returns Promise<HttpResponse> - An awaitable promise that contains the HTTP response.
Important
This function can't be called in read-only mode.
Examples
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);
}
Examples
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);
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for