curl - HTTPotion.get header 中包含 "Referer"

标签 curl elixir

这是我第一次使用 Elixir,因此我的第一个应用程序遇到了一些问题。我正在尝试在 HTTPotion 的帮助下在 elixir 中实现与以下 curl 请求等效的内容:

$ curl -s -X GET https://secure.us.playstation.com/playstation/psn/profile/public/userData?onlineId=eagon1337 --referer https://secure.us.playstation.com/logged-in/trophies/public-trophies/ | python -mjson.tool
{
    "avatarUrl": "//static-resource.np.community.playstation.net/avatar_m/3RD/UP40731301009_65ED8105B0C68DC79ABC_M.png",
    "curLevel": "3",
    "handle": "eagon1337",
    "isPlusUser": "1",
    "progress": "15",
    "totalLevel": "",
    "trophies": {
        "bronze": "44",
        "gold": "0",
        "platinum": "0",
        "silver": "1"
    }
}

发送以下请求 header :

> GET /playstation/psn/profile/public/userData?onlineId=eagon1337 HTTP/1.1
> User-Agent: curl/7.30.0
> Host: secure.us.playstation.com
> Accept: */*
> Referer: https://secure.us.playstation.com/logged-in/trophies/public-trophies/

我想出了以下 Elixir 代码:

defmodule PS4 do
    def helloWorld do

        name = "eagon1337"
        url = "https://secure.us.playstation.com/playstation/psn/profile/public/userData?onlineId=" <> name
        headers = [{"Accept", "*/*"},
                   {"Host", "secure.us.playstation.com"},
                   {"Referer", "https://secure.us.playstation.com/logged-in/trophies/public-trophies/"},
                   {"User-Agent", "curl/7.30.0"}]

        IO.puts "Getting " <> url

        response = HTTPotion.get url, headers: headers

        IO.puts response.body

    end
end

结果

iex(1)> PS4.helloWorld
Getting https://secure.us.playstation.com/playstation/psn/profile/public/userData?onlineId=eagon1337
** (HTTPotion.HTTPError) req_timedout
    (httpotion) lib/httpotion.ex:209: HTTPotion.handle_response/1
          (ps4) lib/ps4.ex:14: PS4.helloWorld/0

针对 http://httpbin.org/get 运行整个请求结果是一个非常平滑的 header (另外删除了“host” header ):

iex(1)> PS4.helloWorld
Getting httpbin.org/get
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "0", 
    "Host": "httpbin.org", 
    "Referer": "https://secure.us.playstation.com/logged-in/trophies/public-trophies/", 
    "User-Agent": "curl/7.30.0"
  }, 
  "origin": "92.77.68.151", 
  "url": "http://httpbin.org/get"
}

:ok

显然,所请求的 URL 需要一个特定的 Referer。但为什么它可以与curl一起使用,而不是通过我的Elixir方法呢?我错过了什么?

最佳答案

这不是直接答案,但使用 http://us.playstation.com/ 而不是 https://secure.us.playstation.com 似乎有效。所以我想这可能与ssl部分有关(还没有找到背景)。

关于curl - HTTPotion.get header 中包含 "Referer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31214270/

相关文章:

erlang - 如何检查 Phoenix/Elixir/Erlang 应用程序的正常运行时间?

php - 如何调试或修复 cURL errno 35

php - PHP 上的 -F Curl 选项

elixir - mix 在代理后面不起作用

Elixir 数据类型的应用

elixir - 无法编译简单的 Elixir 项目

elixir - Phoenix框架自定义 channel

bash - 如何将 curl 跟踪输出捕获到日志文件中

PHP stream_context_set_option SSL 证书作为字符串

json - 如何在 bash 脚本中的 curl 中将多行 json 字符串作为正文发布