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

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
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

We're in Beta

About us Mission Statement