如何获取QQ昵称 - 使用JSONP跨域解决方案
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>获取QQ名字</title>
<style>
</style>
</head>
<body>
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
};
xhr.open("GET","http://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=3338007395");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
xhr.send("");
</script>
</body>
</html>用JSONP解决内容:跨域问题:
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>获取QQ名字</title>
<script>
function jsonpCallback(data){
console.log(data);
}
</script>
</head>
<body>
<script src="http://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=3338007395&callback=jsonpCallback"></script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/oBLK 著作权归作者所有。请勿转载和采集!