【发布时间】:2017-07-23 04:56:30
【问题描述】:
当用户代理使用javascript curl 时,如何从浏览器返回不同的响应?
例如:
if user agent is curl
return /feed.json
else
return index.html
这是我拥有的代码,但是当我运行命令 curl http://example.com 时,它只返回 html 响应
<script>
function browserRedirect(){
var userAgent = navigator.userAgent.toLowerCase();
console.log(userAgent);
var curl = userAgent.match(/curl|PycURL/i) == "curl";
var chrome = userAgent.match(/chrome/i) == "chrome";
// Check that the user agent is curl
if(curl) {
window.location.href = "/feed.json"
}
}
browserRedirect()
</script>
【问题讨论】:
标签: javascript json curl user-agent http-get