大佬教程收集整理的这篇文章主要介绍了curl – 标题中带有“Referer”的HTTPotion.get,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$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","@R_316_10586@lLevel": "","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方法?我错过了什么?
以上是大佬教程为你收集整理的curl – 标题中带有“Referer”的HTTPotion.get全部内容,希望文章能够帮你解决curl – 标题中带有“Referer”的HTTPotion.get所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。