0
后,我试图模仿与HTTPoison curl命令在凤凰应用httpoison遵循重定向后
curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD "$HOST/authenticated/j_security_check"
我收到了一个异步响应,但我没有看到我的身体从卷曲会。我是否错过了HTTPoision调用中的另一个选项?
HTTPoison.post("HOST/authenticated/j_security_check", {:form, [j_username: 'USERNAME', j_password: 'PASSWORD']}, %{"Content-type" => "application/x-www-form-urlencoded", "User-Agent" => "test"}, hackney: [:insecure], hackney: [cookie: elem(acookie, 1).headers], follow_redirect: true)
POST响应是302.这在'curl'中也是一样的;但是,它会重新导向并回复。而HTTPoison中的呼叫则没有。也许我没有正确发送cookie。 cookie来自'acookie = HTTPoison.get“HOST/authenticated/identity”,%{“User-Agent”=>“test”},hackney:[:insecure]'然后在上面的调用中传递。这看起来正确吗?我从[hackney文档]中看到(https://github.com/benoitc/hackney/blob/master/doc/hackney.md#cookies1) – BDESHAZ
在你的问题中使用'HTTPoison.post'; hackney只有在使用post时的状态为'303'时才会遵循重定向。你需要匹配'{ok,maybe_redirect,Status,Headers,Client}'并自己发布'HTTPoison.get' – Krut