pramsky
Hello!
I have the following curl request (confirmed working)
curl --request POST \
--url https://example.net \
--header 'Authorization: Bearer asupersecrettokentoauthenticatewith' \
--header 'Content-Type: multipart/form-data' \
--form orgid=1234567890987654321 \
--form from=5555555555 \
--form to=1234 \
--form 'file=@"/tmp/foo.png"'
I created the multipart payload and posted as as
filepath = "/tmp/foo.png"
orgid = "1234567890987654321"
from = "5555555555"
to = "1234"
form = [{:file, filepath}, {"from", from}, {"to", to}, {"orgid", orgid}]
headers = [
"Content-Type": "multipart/form-data",
"Authorization": "Bearer asupersecrettokentoauthenticatewith"
]
options = []
HTTPoison.post("https://example.net", {:multipart, form}, headers, options)
The HTTPoison request does not seem to work. Am I missing something in the translation ?
Thanks
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #ai
- #graphql
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
pdgonzalez872
what’s the error you are getting @pramsky ?
pramsky
The vendor endpoint returns an error 400.
To debug, I did the 2 posts to pipedream and see there is a difference in the content type used for the form fields.
The curl request
Httpoison request
al2o3cr
Can you extract the actual contents of the two requests?
pramsky
Here are the responses when sent to httpbin.org/anything. Converted to elixir map.
This is the json response from the curl request
This is the response from HTTPoison
al2o3cr
I don’t think comparing what comes out of HTTPBin’s parser is sufficient to see the issue - I only see two differences:
boundarystring in theContent-Type; that’s intentionally random and so not relevantAcceptheader from Curl is not present in the otherIt’s worth a try to add that header; some HTTP implementations are more selective about the headers they expect.
Otherwise you’ll need the actual bytes being sent in the two requests - there’s evidently some difference, since Pipedream shows a slightly different shape, despite HTTPBin seeing the same values.
pramsky
I was able to get the post text fields to show up in pipe dream as text by adding [“Content-Type”: “text/plain”] to the payload tuple.
It still does not work on the vendor site. I reached out to the vendor and he suggested it may be the boundary that is causing the issue. I have the logs of the POST request from the vendor.
The working request via Insomnia REST Client
The non working HTTPoison request
al2o3cr
The boundary from HTTPoison meets the requirements of RFC2046 - it’s more than 1 and less than 70 characters from the specified character set. If the vendor’s parser is breaking on it, the vendor’s parser is broken.
These logs show that the vendor’s parser might be broken (there’s no data printed from the second one) but they offer no suggestion of what the problem is. The only thing that can tell us what’s going on is the raw bytes actually sent to the server.
One way to capture these is with
netcat(frequently shortened tonc) - a handy utility program that will listen on a specified port and then print exactly what comes in when invoked with-lFor
curl:Versus the result from HTTPoison:
Notable differences:
Content-LengthheadersContent-TypeheadersYou could try passing an explicit
Content-Typeto the form fields; there are bug reports that suggest that some servers don’t handleapplication/octet-streamfields correctly. For instance, pass{"from", from, [{"content-type", "text/plain"}]}instead of{"from", from}. Doing this locally has the desired effect (thecontent-typevalues change for the form fields).On the other hand, apparently some servers don’t like
Content-Length:https://github.com/edgurgel/httpoison/issues/286
pramsky
Thanks for the response @al2o3cr
I believe you may be right about the content-length. I setup a local server to capture raw post dumps and could not really see why the httpoison request would fail while the insomnia request works fine as both requests looked correct. Testing it with pipedream showed no errors and I was able to download the attached file.
If some servers don’t like content length on the fields, that would explain why I get a request 400 from this vendor. I reached out to them asking about it.
pramsky
@al2o3cr
The vendor made a fix on their end and the posts are working without issues. Thanks for your help!