Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created July 25, 2012 22:18
Show Gist options
  • Save pullmonkey/3179054 to your computer and use it in GitHub Desktop.
Save pullmonkey/3179054 to your computer and use it in GitHub Desktop.
httpi with curb (spnego and multipart file upload)
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
@anipendakur
Copy link

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

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