How to send POST with multipart / form-data using Power Query Web.Contents

In Power Query, I can load data from Web using Web.Contents function, but there is an api where the request should contain multipart / form data in the following format

"__rdxml"=<*Some data*>

So how do you do this using the Web.Contents function?

I tried doing

...
PostContent = "__rdxml=<*Some data*>",
Source Web.Contents(url,Content=Text.ToBinary(PostContent))
...

      

But the server response from 400 Bad Request

.

I checked the raw request with Fiddler, it looks like the request is not being sent with a header content-type=multipart/form-data

.

I tried to manually add the title of the content type using content-type=multipart/form-data

, but that doesn't work either. The same 400 Bad Request

in the answer.

Any idea?

+2


source to share


1 answer


multipart / form-data is a pretty complex encoding requiring a bunch of MIME specific headers. First I would try to see if application / x-www-form-urlencoded could be used instead:

let
    actualUrl = "http://some.url",
    record = [__rdxml="some data"],
    body = Text.ToBinary(Uri.BuildQueryString(record)),
    options = [Headers =[#"Content-type"="application/x-www-form-urlencoded"], Content=body],
    result = Web.Contents(actualUrl, options)
in
    result

      



EDIT: I have given an example using multipart / form-data with Power Query. It's at https://gist.github.com/CurtHagenlocher/b21ce9cddf54e3807317

+3


source







All Articles