谷歌浏览器通过network模拟HTTP中的GET/POST请求获取response

1、F12打开network选中需要模拟的方法Copy->Copy as fetch

2、通过AI帮你进行转换一下调用格式 

原代码

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"
});

通过文心一言转换(有条件的可以用ChatGPT)

问题:帮我转换为js

转换之后的代码

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返回结果data值

{
	"success": true,
	"data": [{
		"result": true,
		"code": "00000",
		"message": "调用成功",
		"version": "1.0",
		"timestamp": "1705564175452",
		"success": true,
		"msgInfo": "调用成功",
		"msgCode": "SUCCESS",
		"traceId": "213370a117055641752194003ea27f",
		"data": {
			"bdCallConfig": {
				"fromPhone": "19999999999"
			},
			"callTarget": {
				"targetName": "商丘苹果旗舰店",
				"targetId": "202203178800000011705304827Z1E80",
				"targetSubId": "B0FFFFZ1E8",
				"toPhoneShield": "18888888888"
			},
			"channel": "RONG_LIAN_YUN"
		}
	}],
	"code": "00000"
}

比如我这边想获取到toPhoneShield的值

老规矩通过文心一言提问(有条件的可以用ChatGPT)

问题:帮我用js获取到toPhoneShield

结果如下:

const jsonString = `  
{  
  "success": true,  
  "data": [{  
    "result": true,  
    "code": "00000",  
    "message": "调用成功",  
    "version": "1.0",  
    "timestamp": "1705564175452",  
    "success": true,  
    "msgInfo": "调用成功",  
    "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

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-21 10:42:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-21 10:42:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-21 10:42:01       87 阅读
  4. Python语言-面向对象

    2024-01-21 10:42:01       96 阅读

热门阅读

  1. GBASE南大通用示例:创建 NOVALIDATE 方式的约束

    2024-01-21 10:42:01       54 阅读
  2. C# Static与拓展方法

    2024-01-21 10:42:01       56 阅读
  3. python插件架构介绍

    2024-01-21 10:42:01       57 阅读
  4. [go] 组合模式

    2024-01-21 10:42:01       46 阅读
  5. Swift 分类继承

    2024-01-21 10:42:01       50 阅读
  6. springboot使用配置文件配置我们自己配置类的值

    2024-01-21 10:42:01       58 阅读
  7. ROS 2 Humble (Ubuntu Jammy)安装配置

    2024-01-21 10:42:01       67 阅读
  8. SpringSecurity(10)——Csrf防护

    2024-01-21 10:42:01       43 阅读
  9. React Hooks 基本使用

    2024-01-21 10:42:01       44 阅读
  10. 【Ubuntu】使用NFS共享挂载硬盘

    2024-01-21 10:42:01       56 阅读
  11. 数据库学习计划

    2024-01-21 10:42:01       60 阅读
  12. PHP服务报错500的排查过程

    2024-01-21 10:42:01       37 阅读