Created
July 25, 2012 22:18
-
-
Save pullmonkey/3179054 to your computer and use it in GitHub Desktop.
httpi with curb (spnego and multipart file upload)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'httpi' | |
require 'curb' | |
# at some point before the request is made you'll need a kerberos ticket | |
# i.e., kinit -k -t ticket_path | |
image_path = "/tmp/some_image.jpg" | |
url = URI.escape("https://some_ssl_spnego_url.com/upload_file_here") | |
HTTPI.adapter = :curb | |
req = HTTPI::Request.new | |
req.url = url | |
# add the file to the body as a PostField | |
req.body = Curl::PostField.file("image", image_path){IO.read(image_path)} | |
# use spnego when in prod and devserver | |
req.auth.gssnegotiate | |
resp = HTTPI.post req do |http| | |
http.use_ssl | |
http.multipart_form_post = true | |
end | |
if resp.code == 200 | |
puts "Successfully uploaded image." | |
else | |
puts "Error .... :(" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
What if I wanted to send JSON data to my url instead of a file. Could you please tell me how to do that?
Best,
ANi