fix multipart example

pull/428/head
Lucas Nogueira 2 years ago
parent 4bc57234f5
commit 4d77e65314
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -34,9 +34,12 @@
const response = await tauriFetch("http://localhost:3003", options);
const body =
bodyType === "json" ? await response.json() : await response.text();
onMessage({
url: response.url,
status: response.status,
ok: response.ok,
headers: Object.fromEntries(response.headers.entries()),
body,
});
}
@ -45,23 +48,20 @@
let foo = "baz";
let bar = "qux";
let result = null;
let multipart = true;
async function doPost() {
const form = new FormData();
form.append("foo", foo);
form.append("bar", bar);
const response = await tauriFetch("http://localhost:3003", {
method: "POST",
body: {
foo,
bar,
},
headers: multipart
? { "Content-Type": "multipart/form-data" }
: undefined,
body: form,
});
result = {
url: response.url,
status: response.status,
headers: JSON.parse(JSON.stringify(response.headers)),
ok: response.ok,
headers: Object.fromEntries(response.headers.entries()),
body: await response.text(),
};
}
@ -96,11 +96,6 @@
<input class="input" bind:value={bar} />
</div>
<br />
<label>
<input type="checkbox" bind:checked={multipart} />
Multipart
</label>
<br />
<br />
<button class="btn" type="button" on:click={doPost}> Post it</button>
<br />

Loading…
Cancel
Save