Follow the end Url in Erlang

2019-07-28 03:34发布

I'm trying to follow a Url which is in a RSS to find the end URL! so for example I have this URL "http://coder.io/~a27983554a" and the result of following this will be "http://ferd.ca/code-janitor-nobody-s-dream-everyone-s-job-and-how-erlang-can-help.html"

The end URL is saved in the header of the first URL, but the problem is I need to send a request to that URL to get response containing the end result for me!

I'm using this command

{ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://coder.io/~a27983554a")

but this just give me the Headers of the file but the response from the site containing my result

Please help me I'm new in Erlang and it will be perfect if you can provide simple line of code for example

Thanks in advance

标签: erlang
1条回答
爷的心禁止访问
2楼-- · 2019-07-28 04:06

You need to disable autoredirect when performing the request:

Method = get,
Url = "http://coder.io/~a27983554a",
HTTPOptions = [{autoredirect, false}],
{ok, {{_Version, 302, _StatusMsg}, Headers, Body}} =
    httpc:request(Method, {Url, []}, HTTPOptions, []),
Location = proplists:get_value("location", Headers).
查看更多
登录 后发表回答