1、F12打開(kāi)network選中需要模擬的方法Copy->Copy as fetch
2、通過(guò)AI幫你進(jìn)行轉(zhuǎn)換一下調(diào)用格式?
原代碼
fetch("https://mp.amap.com/api/forward/aggregate?mtop.alsc.kbt.intergration.toolkit.call.queryCallBlockInfo", {
"headers": {
"accept": "application/json",
"accept-language": "zh-CN,zh;q=0.9",
"content-type": "application/json;charset=UTF-8",
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://mp.amap.com/biz/crm/exhibition/private",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "{\"requests\":[{\"action\":\"mtop.alsc.kbt.intergration.toolkit.call.queryCallBlockInfo\",\"param\":{\"targetId\":\"202203178800000011705304827Z1E80\",\"businessOperateType\":\"CREATE_ORDER\",\"targetType\":\"LEADS_ENTITY\",\"bizChannel\":\"CRM\"},\"requestType\":\"msePc\",\"extraHeader\":{}}]}",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
通過(guò)文心一言轉(zhuǎn)換(有條件的可以用ChatGPT)
問(wèn)題:幫我轉(zhuǎn)換為js
轉(zhuǎn)換之后的代碼
fetch("https://mp.amap.com/api/forward/aggregate?mtop.alsc.kbt.intergration.toolkit.call.queryCallBlockInfo", {
method: "POST",
headers: {
"Accept": "application/json",
"Accept-Language": "zh-CN,zh;q=0.9",
"Content-Type": "application/json;charset=UTF-8",
"Sec-Ch-UA": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"Sec-Ch-UA-Mobile": "?0",
"Sec-Ch-UA-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin"
},
referrer: "https://mp.amap.com/biz/crm/exhibition/private",
referrerPolicy: "strict-origin-when-cross-origin",
body: JSON.stringify({
requests: [
{
action: "mtop.alsc.kbt.intergration.toolkit.call.queryCallBlockInfo",
param: {
targetId: "202203178800000011705304827Z1E80",
businessOperateType: "CREATE_ORDER",
targetType: "LEADS_ENTITY",
bizChannel: "CRM"
},
requestType: "msePc",
extraHeader: {}
}
]
}),
mode: "cors",
credentials: "include"
})
.then(response => response.json())
.then(data => console.log(data))
.catch((error) => console.error("Error:", error));
?3、拿到response返回結(jié)果data值
{
"success": true,
"data": [{
"result": true,
"code": "00000",
"message": "調(diào)用成功",
"version": "1.0",
"timestamp": "1705564175452",
"success": true,
"msgInfo": "調(diào)用成功",
"msgCode": "SUCCESS",
"traceId": "213370a117055641752194003ea27f",
"data": {
"bdCallConfig": {
"fromPhone": "19999999999"
},
"callTarget": {
"targetName": "商丘蘋果旗艦店",
"targetId": "202203178800000011705304827Z1E80",
"targetSubId": "B0FFFFZ1E8",
"toPhoneShield": "18888888888"
},
"channel": "RONG_LIAN_YUN"
}
}],
"code": "00000"
}
比如我這邊想獲取到toPhoneShield的值
老規(guī)矩通過(guò)文心一言提問(wèn)(有條件的可以用ChatGPT)
問(wèn)題:幫我用js獲取到toPhoneShield文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-816561.html
結(jié)果如下:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-816561.html
const jsonString = `
{
"success": true,
"data": [{
"result": true,
"code": "00000",
"message": "調(diào)用成功",
"version": "1.0",
"timestamp": "1705564175452",
"success": true,
"msgInfo": "調(diào)用成功",
"msgCode": "SUCCESS",
"traceId": "213370a117055641752194003ea27f",
"data": {
"bdCallConfig": {
"fromPhone": "19999999999"
},
"callTarget": {
"targetName": "商丘蘋果旗艦店",
"targetId": "202203178800000011705304827Z1E80",
"targetSubId": "B0FFFFZ1E8",
"toPhoneShield": "18888888888"
},
"channel": "RONG_LIAN_YUN"
}
}],
"code": "00000"
}
`;
const data = JSON.parse(jsonString);
const toPhoneShield = data.data[0].data.callTarget.toPhoneShield;
console.log(toPhoneShield); // 輸出: 18888888888
到了這里,關(guān)于谷歌瀏覽器通過(guò)network模擬HTTP中的GET/POST請(qǐng)求獲取response的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!