Nicolas
Hi,
I have this URL https://beerfactory.org/api/v1/apps which redirects (HTTP 301) to https://mastodon.beerfactory.org/api/v1/apps.
When using HTTPoison to post of this URL with the following code to follow the redirection:
HTTPoison.request(:post, "https://beerfactory.org/api/v1/apps", "", [], [follow_redirect: true])
I get the following result :
{:ok,
%HTTPoison.AsyncResponse{
id: {:maybe_redirect, 301,
[
{"Server", "nginx/1.14.0 (Ubuntu)"},
{"Date", "Mon, 29 Oct 2018 21:45:22 GMT"},
{"Content-Type", "text/html"},
{"Content-Length", "194"},
{"Connection", "keep-alive"},
{"Location", "https://mastodon.beerfactory.org/api/v1/apps"}
],
{:client, {1540, 849522, 427514}, {:metrics_ng, :metrics_dummy},
:hackney_ssl, 'beerfactory.org', 443, "beerfactory.org",
[max_redirect: 5, follow_redirect: true],
{:sslsocket, {:gen_tcp, #Port<0.7>, :tls_connection, :undefined},
[#PID<0.204.0>, #PID<0.203.0>]},
{:default, #Reference<0.4243972227.2875195393.28572>,
{'beerfactory.org', 443, :hackney_ssl}, #PID<0.199.0>, :hackney_ssl},
#Reference<0.4243972227.2875195393.28572>, true, :hackney_pool, 5000, true,
5, false, 5, nil, nil,
{:hparser, :response, 4096, 10, 0, :on_body,
"<html>\r\n<head><title>301 Moved Permanently</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>301 Moved Permanently</h1></center>\r\n<hr><center>nginx/1.14.0 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n",
{1, 1}, "", [], 194, "", "keep-alive", "text/html",
"https://mastodon.beerfactory.org/api/v1/apps", :waiting},
{6,
{:dict, 6, 16, 16, 8, 80, 48,
{[], [], [], [], [], [], [], [], [], [], [], ...},
{{[["content-length", {3, "Content-Length", "194"}]],
[
[
"location",
{5, "Location", "https://mastodon.beerfactory.org/api/v1/apps"}
]
], [["date", {1, "Date", "Mon, 29 Oct 2018 21:45:22 GMT"}]], [], [],
[["server", {...}]], [], [], [], ...}}}}, :connected, :waiting, nil,
:normal, false, false, false, :undefined, false, &:hackney_request.send/2,
:waiting, nil, 4096, "", [], {1, 1}, 194, nil, nil, "POST", "/api/v1/apps",
...}}
}}
Is there a way I can get the redirection target body from this result ?
Thanks.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicolas
Note that when trying the same code with another endpoint which is also redirected but with GET method the redirection works, so may be the automatic redirection works differently with the POST method.
details:
whereas:
frigidcode
POST redirects should use 307 according to the spec. 301 would require prompting the user for anything other than HEAD/GET verbs. It appears HTTPoison is acting as it should by not following the POST redirect.
As for your first question I will play with it and see if I can get the location parsed out.
frigidcode
quick solution, might be cleaner ones available (very tired ATM)
Nicolas
OK, reading hackney documentation and source code it appears that hackney doesn’t follow 301/302 redirection unless you add
force_redirect: truein the options:In my example, the redirection is followed when both
follow_redirectandforce_redirectare specified:422 status is due to the bad request format used for this example.