Tauri Body
要用于 POST 和 PUT 请求的 body 对象。
Since: 1.0.0
性能
payload
payload: unknown
Defined in: http.ts:95
type
type: string
Defined in: http.ts:94
Methods
bytes
Static bytes(: <> | ArrayBuffer | <>): BodybytesIterablenumberArrayLikenumber
创建新的字节数组体。
例
import { Body } from "@tauri-apps/api/http"
Body.bytes(new Uint8Array([1, 2, 3]));
参数
| 名字 | 类型 | 描述 |
|---|---|---|
bytes
|
Iterable<number> | ArrayBuffer | ArrayLike<number> |
body 字节数组 |
Returns: Body
准备用于 POST 和 PUT 请求的 body 对象。
form
Static form(: Record<, Part> | FormData): Bodydatastring
创建新的表单数据正文。表单数据是一个对象,其中每个键都是条目名称, 该值是字符串或文件对象。
默认情况下,它设置 Content-Type 标头, 但您可以将其设置为是否启用了 Cargo 功能。application/x-www-form-urlencodedmultipart/form-datahttp-multipart
请注意,允许列表范围内必须允许文件路径。fs
例
import { Body } from "@tauri-apps/api/http"
const body = Body.form({
key: 'value',
image: {
file: '/path/to/file', // either a path or an array buffer of the file contents
mime: 'image/jpeg', // optional
fileName: 'image.jpg' // optional
}
});
// alternatively, use a FormData:
const form = new FormData();
form.append('key', 'value');
form.append('image', file, 'image.png');
const formBody = Body.form(form);
参数
| 名字 | 类型 | 描述 |
|---|---|---|
data
|
Record<, Part> | FormDatastring
|
正文数据 |
Returns: Body
准备用于 POST 和 PUT 请求的 body 对象。
json
Static json(: Record<, >): Bodydataanyany
创建新的 JSON 正文。
例
import { Body } from "@tauri-apps/api/http"
Body.json({
registered: true,
name: 'tauri'
});
参数
| 名字 | 类型 | 描述 |
|---|---|---|
data
|
Record<, anyany> |
正文 JSON 对象 |
Returns: Body
准备用于 POST 和 PUT 请求的 body 对象。
text
Static text(: ): Bodyvaluestring
创建新的 UTF-8 字符串正文。
例
import { Body } from "@tauri-apps/api/http"
Body.text('The body content as a string');
参数
| 名字 | 类型 | 描述 |
|---|---|---|
value | string | 正文字符串。 |
Returns: Body
准备用于 POST 和 PUT 请求的 body 对象。