How does wttr.in respond differently to browsers than it does curl?

天涯浪子 提交于 2020-01-06 04:19:25

问题


If you go to http://wttr.in/ in your browser you'll see a page which is wrapped in a tag, has links, and is colored using spans.

If you then go to terminal and type curl http://wttr.in/ you'll get pretty much exactly the same looking page, but the code is very different.

How does wttr.in differentiate between these two?

I'm aware of this existing question (How can I tell a curl request vs browser request), but as the answer is "you can't" and I'm seeing proof you can, it seemed like a poor reference.

Also, I'm not worried about spoofing.


回答1:


Found it. The headers from a default curl contain

headers: { host: 'localhost:3000', 'user-agent': 'curl/7.54.0', accept: '/' },

While the headers from my browser are like so:

headers: { host: 'localhost:3000', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'accept-language': 'en-US,en;q=0.5', 'accept-encoding': 'gzip, deflate', connection: 'keep-alive', 'upgrade-insecure-requests': '1', 'cache-control': 'max-age=0' },

The big difference between the two being the "user-agent" argument




回答2:


But I believe you can still spoof by setting the user agent with curl command.



来源:https://stackoverflow.com/questions/51750342/how-does-wttr-in-respond-differently-to-browsers-than-it-does-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!