HTTPoison.get() Elixir 错误
HTTPoison.get() error in Elixir
我有以下 URL
https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200
并且需要通过HTTPoison.get获取页面body。
下面的方法给出超时错误
case HTTPoison.get("https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200", []) do
{:ok, %HTTPoison.Response{body: body}} ->
{:ok, body}
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
end
对于其他 URL 它有效,似乎是由于 URL
中的特定模式引起的错误
和Elixir/HTTPoison没有太大关系。本站已根据要求设置限额header.
Curl 仅适用于 headers,例如:
curl 'https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' -H 'Connection: keep-alive' -H 'Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2'
您还需要在 HTTPoison
中设置这些 header。
我有以下 URL
https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200
并且需要通过HTTPoison.get获取页面body。 下面的方法给出超时错误
case HTTPoison.get("https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200", []) do
{:ok, %HTTPoison.Response{body: body}} ->
{:ok, body}
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
end
对于其他 URL 它有效,似乎是由于 URL
中的特定模式引起的错误和Elixir/HTTPoison没有太大关系。本站已根据要求设置限额header.
Curl 仅适用于 headers,例如:
curl 'https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' -H 'Connection: keep-alive' -H 'Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2'
您还需要在 HTTPoison
中设置这些 header。