seed-rs / seed

A Rust framework for creating web apps
MIT License
3.81k stars 155 forks source link

No way to POST Content-Type=application/x-www-form-urlencoded #638

Closed torhovland closed 1 year ago

torhovland commented 3 years ago

I need to POST form data to an endpoint that requires Content-Type=application/x-www-form-urlencoded. Specifically, this is an OAuth2 endpoint that doesn't seem to support JSON form data.

glennsl commented 3 years ago

There are FormData bindings here: https://github.com/seed-rs/seed/blob/master/src/browser/fetch/form_data.rs

They just haven't been released yet.

(This also reminds me that I was supposed to make you an example for the leaflet bindings. Hopefully this weekend!)

torhovland commented 3 years ago

Actually, that didn't quite work either. It insists on multipart/form-data, while I need application/x-www-form-urlencoded.

However, I found I could just do this:

Request::new(url)
        .method(Method::Post)
        .text(format!(
            "grant_type=authorization_code&redirect_uri=http://127.0.0.1:8088/callback&code={}",
            code
        ))
        .header(Header::content_type("application/x-www-form-urlencoded"))
        .fetch()

Perhaps this is as good as it gets, though. See https://stackoverflow.com/a/37562814

glennsl commented 3 years ago

Oh right, you could probably also use UrlSearchParams.

flosse commented 1 year ago

obsolete since v0.10.0