Shortcuts App (Get Contents of URL) not setting Headers correctly for POST request

I'm using the Shortcuts App "Get Contents of URL" to make an API Request. (As documented at https://support.apple.com/guide/shortcuts/request-your-first-api-apd58d46713f/ios )


The POST request that I'm making needs a specific Header for FORM data, namely: "Content-Type: application/x-www-form-urlencoded"


However, when I enter this into the "Get Contents of URL" options, it doesn't work.


I'm specifying "Form" as the data type and "Content-Type: application/x-www-form-urlencoded" for the Header option.


It seems like the Shortcuts App always ignores the "Content-Type" Header setting.


Does anyone else have this issue?

iPad Pro 12.9-inch, 3rd Gen, Wi-Fi

Posted on Jul 9, 2020 11:36 AM

Reply
2 replies

Jul 17, 2020 4:13 PM in response to Spaceman Ned

I just solved this right before you posted. User error, duh.


It wasn't the Content-Type Header after all, but a Base64 encoded string that I was using in another Header. It turns out that the default setting of the Base64 item in Shortcuts is to truncate (line wrap) the string at 76 characters. Once I found the option and changed it to "None" (so that the Base64 string was unmodified) then the API call started working.


A colleague using Fiddler Proxy helped me capture the HTTPS requests and find that the Content-Type was correct, but the Base64 encoded Header was truncated.


Even so, your info is very useful and I'll definitely be trying it next time I post Form data. Thanks!

Jul 16, 2020 7:41 PM in response to OhTheCloudy

I’ve been having this same problem for days and I think I finally found the answer:


For application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string -- name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=). An example of this would be: 

MyVariableOne=ValueOne&MyVariableTwo=ValueTwo


Found this at https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data just minutes after seeing your post.


I took all of my form data and put

it into a text block in the format key1=text1&key2=text2 etc. then set the request body to File and selected the text block as my magic variable. Worked for me.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Shortcuts App (Get Contents of URL) not setting Headers correctly for POST request

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.