1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Add support for a HTTP body for POST (#139)

Closes https://github.com/emilk/egui/issues/137

Co-authored-by: Emil Ernerfeldt <emilernerfeldt@gmail.com>
This commit is contained in:
PauloMelo
2021-01-26 20:32:16 +00:00
committed by GitHub
parent 1ac1a72fa8
commit eedb63bb3b
3 changed files with 25 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ pub async fn fetch_async(request: &Request) -> Result<Response, String> {
/// NOTE: Ok(..) is returned on network error.
/// Err is only for failure to use the fetch api.
async fn fetch_jsvalue(request: &Request) -> Result<Response, JsValue> {
let Request { method, url } = request;
let Request { method, url, body } = request;
// https://rustwasm.github.io/wasm-bindgen/examples/fetch.html
@@ -24,6 +24,10 @@ async fn fetch_jsvalue(request: &Request) -> Result<Response, JsValue> {
opts.method(method);
opts.mode(web_sys::RequestMode::Cors);
if !body.is_empty() {
opts.body(Some(&JsValue::from_str(body)));
}
let request = web_sys::Request::new_with_str_and_init(&url, &opts)?;
request.headers().set("Accept", "*/*")?;