Skip to content

Instantly share code, notes, and snippets.

@narath
Created May 8, 2017 17:24
How to do a x-www-form-urlencoded post with Faraday
require 'faraday'
require 'uri'
data = {
:your_data => "YOUR DATA"
}
url = "some url"
response = Faraday.post(url) do |req|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = URI.encode_www_form(data)
end
puts response.inspect
@kumasan3
Copy link

kumasan3 commented Oct 2, 2021

loveya

@Ruff9
Copy link

Ruff9 commented Jun 23, 2022

You're a king

@cozynooks
Copy link

Thank you for save my time.

@janwerkhoven
Copy link

janwerkhoven commented Jan 24, 2023 β€’

I have not been able to make "application/x-www-form-urlencoded" requests with with Net::HTTP... πŸ˜‘

With Faraday it worked on first attempt. Thanks! πŸŽ‰

@thiagovsk
Copy link

AMAZING JOB!!!!!!

@Navinnair
Copy link

thanks πŸ‘

@fhyfirman
Copy link

Thanks,
You save my time

@Fedcomp
Copy link

Fedcomp commented Feb 6, 2025

Surprised it's not in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment