Hi,
I try to get html contents for a https webpage using :hackney
but I end up with following error. Any help ?
iex(1)> {:ok, client} = :hackney.request(
:get,
"https://www.linkedin.com",
[],
:stream,
[follow_redirect: true, max_redirect: 5, force_redirect: true]
)
{:ok, #Reference<0.4267035501.2389966851.12907>}
iex(2)> {ok, status, headers, client} = :hackney.start_response(client)
** (MatchError) no match of right hand side value: {:error, :closed}
try this function
:hackney.body(client)
** (FunctionClauseError) no function clause matching in :hackney_http.execute/2
The following arguments were given to :hackney_http.execute/2:
# 1
nil
# 2
""
(hackney) /home/alexandrubagu/devel/proxy-recorder/deps/hackney/src/hackney_http.erl:136: :hackney_http.execute/2
(hackney) /home/alexandrubagu/devel/proxy-recorder/deps/hackney/src/hackney_response.erl:137: :hackney_response.stream_body/1
(hackney) /home/alexandrubagu/devel/proxy-recorder/deps/hackney/src/hackney_response.erl:303: :hackney_response.read_body/3
(hackney) /home/alexandrubagu/devel/proxy-recorder/deps/hackney/src/hackney.erl:505: anonymous fn/1 in :hackney.body/1
On github here’s an example but it doesn’t work:
ReqBody = << "{
\"id\": \"some_paste_id2\",
\"rev\": \"some_revision_id\",
\"changeset\": \"changeset in unidiff format\"
}" >>,
ReqHeaders = [{<<"Content-Type">>, <<"application/json">>}],
Path = <<"https://friendpaste.com/">>,
Method = post,
{ok, ClientRef} = hackney:request(Method, Path, ReqHeaders, stream, []),
ok = hackney:send_body(ClientRef, ReqBody),
{ok, _Status, _Headers, ClientRef} = hackney:start_response(ClientRef),
{ok, Body} = hackney:body(ClientRef),
You shouldnt use stream
{:ok, status, respheaders, client} = :hackney.request( :get, "https://www.linkedin.com", [follow_redirect: true, max_redirect: 5, force_redirect: true] )
Thanks. I saw it works without :stream
but I wonder if is another solution