seed icon indicating copy to clipboard operation
seed copied to clipboard

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

Open torhovland opened this issue 4 years ago • 3 comments

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.

torhovland avatar Nov 22 '21 11:11 torhovland

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!)

glennsl avatar Nov 22 '21 11:11 glennsl

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

torhovland avatar Nov 22 '21 12:11 torhovland

Oh right, you could probably also use UrlSearchParams.

glennsl avatar Nov 22 '21 13:11 glennsl

obsolete since v0.10.0

flosse avatar Mar 07 '23 00:03 flosse