fetch body
This commit is contained in:
parent
98d0af014d
commit
91093ff64b
2 changed files with 30 additions and 4 deletions
|
|
@ -685,13 +685,33 @@ let env = {
|
|||
const response = await fetch(urlStr);
|
||||
const result = await response.text();
|
||||
|
||||
console.log(result);
|
||||
|
||||
const ptr = writeStringToWasm(result);
|
||||
console.log(ptr);
|
||||
|
||||
const { ExecuteFetchHandler} = window.crafter_webbuild_wasi.instance.exports;
|
||||
console.log("callback");
|
||||
ExecuteFetchHandler(handlerID, ptr);
|
||||
WasmFree(ptr);
|
||||
|
||||
} catch (error) {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
fetchWithBody: async function(url, urlLenght, body, bodyLength, handlerID) {
|
||||
try {
|
||||
const urlStr = decoder.decode(new Int8Array(window.crafter_webbuild_wasi.instance.exports.memory.buffer, url, urlLenght));
|
||||
const bodyStr = decoder.decode(new Int8Array(window.crafter_webbuild_wasi.instance.exports.memory.buffer, body, bodyLength));
|
||||
|
||||
const response = await fetch(urlStr, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: bodyStr
|
||||
});
|
||||
const result = await response.text();
|
||||
|
||||
const ptr = writeStringToWasm(result);
|
||||
|
||||
const { ExecuteFetchHandler} = window.crafter_webbuild_wasi.instance.exports;
|
||||
ExecuteFetchHandler(handlerID, ptr);
|
||||
WasmFree(ptr);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue