WEB端调试有时需要将接口请求拿到本地调试,可以通过postman、apifox等工具发起接口调用,一个接口请求往往涉及到接口路径、请求Header、请求体等信息,通过手动方式显得效率较低,今天给大家介绍一种快捷导入接口的方式,在需要的时候能想起来就行。
步骤一
打开浏览器控制台,鼠标右键复制对应请求,这里以百度相关请求为例。
![image.png](https://cdn.nlark.com/yuque/0/2024/png/26851474/1725179388361-246f72e9-2661-44f7-ad2a-730cab2e313f.png#averageHue=%23e6e4e3&clientId=ud01d6704-aeab-4&from=paste&height=1138&id=u4b995ed5&originHeight=2276&originWidth=3198&originalType=binary&ratio=2&rotation=0&showTitle=false&size=1095535&status=done&style=none&taskId=u9fc1ad1e-6448-4244-bd83-603e81cf5ff&title=&width=1599)
复制后的cURL格式如下:
1 2 3 4 5 6 7 8 9 10 11 12
| curl 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=zh&dt=t&dt=bd&dj=1&q=test' \ -H 'accept: */*' \ -H 'accept-language: zh-CN,zh;q=0.9' \ -H 'cache-control: no-cache' \ -H 'dnt: 1' \ -H 'pragma: no-cache' \ -H 'priority: u=1, i' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: none' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \ -H 'x-client-data: CKbfygE='
|
步骤二
将复制的cURL格式导入到API客户端,这里以apifox为例。
![image.png](https://cdn.nlark.com/yuque/0/2024/png/26851474/1725179503355-ef016d98-949e-463b-850a-3233d7da924b.png#averageHue=%23d0cbbf&clientId=ud01d6704-aeab-4&from=paste&height=220&id=u8b68b21f&originHeight=440&originWidth=548&originalType=binary&ratio=2&rotation=0&showTitle=false&size=69000&status=done&style=none&taskId=u8fa1981a-41d3-4a66-85d8-7ee3557bfac&title=&width=274)
![image.png](https://cdn.nlark.com/yuque/0/2024/png/26851474/1725179548175-3630d076-aad1-4d27-a809-0b7340575eb7.png#averageHue=%23d8d0c3&clientId=ud01d6704-aeab-4&from=paste&height=224&id=u8b1b386e&originHeight=447&originWidth=987&originalType=binary&ratio=2&rotation=0&showTitle=false&size=77607&status=done&style=none&taskId=ubfd9f9b9-1aba-4f33-b0d4-27f8e20a416&title=&width=493.5)
可以看到对应的请求数据均以导入,直接发起接口调用即可,浏览器接口复制功能下还有其他复制方式,感兴趣的小伙伴可以尝试下。
文章原始地址 >>