Skip to content

Instantly share code, notes, and snippets.

@narath
Created May 8, 2017 17:24
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narath/9e74cb7dd17050c76936fded2861f2d1 to your computer and use it in GitHub Desktop.
Save narath/9e74cb7dd17050c76936fded2861f2d1 to your computer and use it in GitHub Desktop.
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
@stephenZ22
Copy link

Thank you my friend

@unfernandito
Copy link

Thanks you, this should be added to faraday documentation

@stevepentler
Copy link

Thanks!

@vvo
Copy link

vvo commented Dec 16, 2019

I wish I could upvote you a million times, thanks

@alexgonor
Copy link

Thanks a lot!

@danielcomas25
Copy link

Thnks!

@KartowkaAteist
Copy link

Thanks mate, a lot

@activeliang
Copy link

thx~

@CarlosLCervantes
Copy link

👍

@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

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