foggy

foggy

Successfully posting JSON w/ :httpc

I have a Phoenix api that needs to make a couple of post requests. I am fully aware that there are easier options for me than calling :httpc from erlang, but I started trying it out and now I’m curious as to why my request is working.

When I make the following request, the Flask API which I’m calling does not register any params being passed in the body. (Note: remember this is calling erlang in elixir and is not raw erlang)

:httpc.request(:post, {'https://thecorrecturl.com', [], 'application/json', 'any body at all'}, [], [])

To be clear, I am successfully hitting the endpoint, it’s just “any body at all” doesn’t get through. I’ve tried different variations of ‘{“key”:“value”}’ but nothing ever gets through (backslashed quotes, backslashed single quotes, nothing).

What am I missing to post this json body?

Marked As Solved

idi527

idi527

:wave:

iex(6)> :httpc.request(:post, {'http://httpbin.org/post', [], 'application/json', 'any body at all'}, [], [])
{:ok,
 {{'HTTP/1.1', 200, 'OK'},
  [
    {'connection', 'keep-alive'},
    {'date', 'Wed, 05 Sep 2018 05:38:54 GMT'},
    {'via', '1.1 vegur'},
    {'server', 'gunicorn/19.9.0'},
    {'content-length', '308'},
    {'content-type', 'application/json'},
    {'access-control-allow-origin', '*'},
    {'access-control-allow-credentials', 'true'}
  ],
  '{\n  "args": {}, \n  "data": "any body at all", \n  "files": {}, \n  "form": {}, \n  "headers": {\n    "Connection": "close", \n    "Content-Length": "15", \n    "Content-Type": "application/json", \n    "Host": "httpbin.org"\n  }, \n  "json": null, \n  "origin": "159.65.119.183", \n  "url": "http://httpbin.org/post"\n}\n'}}

works fine for me. You should probably check your flask app.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
nobody
Hi! In PHP: $SERVER['SERVERADDR'] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30840 112
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement