加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

curl – 标题中带有“Referer”的HTTPotion.get

发布时间:2020-12-13 23:26:44 所属栏目:Linux 来源:网络整理
导读:这是我第一次使用Elixir,所以我的第一个应用程序遇到了一些问题.我试图在HTTPotion的帮助下在elixir中实现以下curl-request的等价物: $curl -s -X GET https://secure.us.playstation.com/playstation/psn/profile/public/userData?onlineId=eagon1337 --re
这是我第一次使用Elixir,所以我的第一个应用程序遇到了一些问题.我试图在HTTPotion的帮助下在elixir中实现以下curl-request的等价物:

$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"
    }
}

发送以下请求标头:

> 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运行整个请求会产生一个非常流畅的标题(另外删除“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部分有关(还没有找到背景).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读