Utilização

Send text, form fields or bytes with fetch.

tsx
// Send text, form fields or bytes with fetch.
async function post(url: string, body: BodyInit) {
  const response = await fetch(url, { method: 'POST', body });

  if (!response.ok) throw new Error(`${url} answered ${response.status}`);
}

await post('https://api.example.com/login', new URLSearchParams({ user: 'ana', remember: '1' }));
await post('https://api.example.com/notes', 'Plain text, sent as UTF-8');
await post('https://api.example.com/upload', new TextEncoder().encode('bytes'));

Construtores

ts
(): TextEncoder

Parâmetros

Sem parâmetros.

Devolve

TextEncoder

Propriedades e métodos 4

NomeTipoObrigatórioDescrição
prototypesó de leituraTextEncoderSim—
encodingsó de leitura"utf-8"Sim—
encode(text?: string) => Uint8ArraySim—
encodeInto(text: string, into: Uint8Array) => { read: number; written: number;}Sim—
encode — assinaturas de método

Assinaturas

ts
(text?: string): Uint8Array

Parâmetros

NomeTipoObrigatórioDescrição
textstringNão—

Devolve

Uint8Array<ArrayBufferLike>

encodeInto — assinaturas de método

Assinaturas

ts
(text: string, into: Uint8Array): { read: number; written: number; }

Parâmetros

NomeTipoObrigatórioDescrição
textstringSim—
intoUint8Array<ArrayBufferLike>Sim—

Devolve

{ read: number; written: number;}

Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.