Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putting data-binary data #380

Closed
ngw opened this issue May 29, 2014 · 4 comments
Closed

putting data-binary data #380

ngw opened this issue May 29, 2014 · 4 comments

Comments

@ngw
Copy link

ngw commented May 29, 2014

Hi, I'm not sure if this is supported at all by faraday, but I'm trying to do and HTTP PUT request with faraday and I'm stuck to what curl calls --data-binary format. The request is:

> curl -X PUT https://your_user_token:@api.80legs.com/v2/urllists/name_of_url_list -H "Content-Type: application/octet-stream" --data-binary "[\"http://www.example.com/\", \"http://www.sample.com/\", \"http://www.test.com/\"]" -i

What I'm trying to do is:

conn = Faraday.new(url: "https://#{token}:@api.80legs.com/v2/urllists/#{name}") do |faraday|
  faraday.request :multipart
  faraday.response :logger
end
conn.put do |req|
  req.headers['Content-Type'] = 'application/octet-stream'
  req.body = url_list.to_s
end

But it doesn't work: https://gist.github.com/ngw/ef5cdb2fb7648016ba1f

Can I do such a request?

@technoweenie
Copy link
Member

That exception is from the :logger middleware and has nothing to do with posting binary data. Also, you should take out the :multipart middleware, that'll try to convert the body to a multipart form post. I don't use the logger middleware, but it looks like the response didn't really finish (no status or response headers).

@mislav
Copy link
Contributor

mislav commented Jun 1, 2014

You did almost everything right, but forgot to state the adapter. You should add the adapter line:

conn = Faraday.new(url: "...") do |faraday|
  faraday.request :multipart
  faraday.response :logger
  faraday.adapter :net_http
end

You don't have to take out the :multipart middleware (@technoweenie's response isn't entirely correct), since the middleware will safely ignore requests with an explicit Content-type. You can leave the logger middleware as well.

@O-I
Copy link
Contributor

O-I commented Feb 1, 2015

@ngw I know this is an older issue, but did mislav's answer of making sure to specify the Faraday adapter solve your problem? If it did, would you mind closing the issue when it's convenient for you? And if there is still some issue, please write back and I'll try to help resolve. 😃 Thanks!

@ngw
Copy link
Author

ngw commented Feb 2, 2015

Yes, no idea why I forgot to close this... Sorry guys

@ngw ngw closed this as completed Feb 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants