1

我有以下网址

https://www.michaelkors.com/four-in-one-logo-belt-box-set/_/R-US_39F6LBLY4B?color=0200

并且需要通过HTTPoison.get获取页面正文。以下方法给出超时错误

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 中的特定模式引起的错误

4

1 回答 1

1

Elixir/HTTPoison 没有太大的问题。该网站已根据请求标头设置了限制。

Curl 仅适用于以下标题:

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.

于 2017-11-07T08:41:38.843 回答