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