Skip to content

Instantly share code, notes, and snippets.

@renzhezhilu
Last active March 1, 2020 08:57
Show Gist options
  • Save renzhezhilu/8ee4316319c39250777cddf235aac363 to your computer and use it in GitHub Desktop.
Save renzhezhilu/8ee4316319c39250777cddf235aac363 to your computer and use it in GitHub Desktop.
[fetch浏览器] #请求
//https://developer.mozilla.org/zh-CN/docs/Web/API/Body
fetch(`https://xxxxxx`)
.then(x=>{
return x.json()
//x.text()
//x.blob()
//x.formData()
//x.arrayBuffer()
}).then(d=>{
console.log(d)
})
// gbk编码,fetch出来的结果乱码了
fetch('http://tieba.baidu.com')
.then(res=> res.blob())
.then(blob => {
var reader = new FileReader();
reader.onload = function(e) {
var text = reader.result;
console.log(text)
}
reader.readAsText(blob, 'GBK')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment