I'm tring to post to an api. This example from the docs works in curl:
curl -k -w %{http_code} -H "Content-Type:text/plain" -u user:pass --data-binary @filename https://server/url/here
This is what I have tried with faraday:
require 'rubygems'
require 'faraday'
require 'pp'
conn = Faraday.new(:url => 'https://server/url/here' , :ssl => {:verify => false} ) do |faraday|
faraday.response :logger
faraday.basic_auth('user', 'pass')
faraday.adapter Faraday.default_adapter
end
data = File.read('teste.txt')
res=conn.post '/' , data
pp res
It posts, I receive a 200 code but something goes wrong. The response is the server's login page.
Is curl -u equivalent to basic auth?
That looks right, the only difference is possibly the content-type in the header, this should work:
I know your question concerns the Faraday gem but here is how I would have done it using the 'rest-client' gem, maybe this can help: