老师哦 我实在看不出我这写的为啥报304 看着一样啊
来源:5-2 歌手数据接口抓取
慕粉3227390
2019-03-21
singer.js如下:
import jsonp from 'common/js/jsonp'
import {commonParams, options} from './config'
// import axios from 'axios'
export function getSingerList() {
const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'
// const url = '/api/v8/fcg-bin/v8.fcg'
const data = Object.assign({}, commonParams, {
channel: 'singer',
page: 'list',
key: 'all_all_all',
pagesize: 100,
pagenum: 1,
hostUin: 0,
needNewCode: 0,
platform: 'yqq'
})
return jsonp(url, data, options)
}
jsonp.js如下:
import originJSONP from 'jsonp'
export default function jsonp(url,data,option) {
url += (url.indexOf('?')<0 ? '?':'&') + param(data)
return new Promise((resolve, reject)=> {
originJSONP(url, option, (err, data)=> {
if(!err) {
resolve(data)
} else {
reject(err)
}
})
})
}
function param(data){
let url=''
for(var k in data){
let value = data[k]== undefined ? '':data[k]
url += `&${k}=${encodeURIComponent(value)}`
}
return url?url.substring(1):''
}
config.js如下:
export const commonParams = {
g_tk: 1928093478,
inCharset: 'utf-8',
outCharset: 'utf-8',
notice: 0,
formate: 'jsonp'
}
export const options = {
param: 'jsonpCallback'
}
export const ERR_OK = 0
写回答
1回答
-
ustbhuangyi
2019-03-21
你把请求的完整的 url 地址贴出来吧
092019-03-21
相似问题