开发者社区> 问答> 正文

【紧急】钉钉桌面端设置“系统内置内核”时,微应用的POST请求的request body被清空

【问题描述】 钉钉桌面端设置“系统内置内核”时,微应用的POST请求的request body被清空,麻烦看下是什么原因? 【操作环境】 操作系统及版本:macOS 11.7 Safari浏览器UA:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15 钉钉桌面端版本:6.5.40 【操作步骤】 1. 钉钉设置中的Web内核设置为“系统内置内核” 2. 钉钉应用配置了我们自己开发的系统,发现POST请求中的request body被清空,导致应用无法正常运行。 3. Web内核设置为“Chromiun内核”时是正常的,在Safari浏览器上运行也是正常的。 4. 我写了个简单demo进行验证,发现window.fetch和XMLHttpRequest请求的body都会被清空

【抓包过程】 Image_20220930175336.png Image_20220930175246.png Image_20220930175051.png Image_20220930174946.png 【代码】

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>测试页面</title>
</head>

<body>
  <button onclick="fetchRequest()">fetch发送请求</button>
  <button onclick="xhrRequest()">原生方法发送请求</button>
</body>
<script>
  function fetchRequest() {
    const body = JSON.stringify({ a: 123, b: 'test' })
    window.fetch('https://www.baidu.com/', {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: "foo=bar&type=fetch",
      // mode: 'cors',
      // credentials: 'include'
    }).then(response => {
      if (response.ok) {
        return response.json()
      } else {
        console.error(response.statusText)
      }
    }).catch(error => {
      console.error('fetch data error:' + error.message)
    })
  }

  function xhrRequest() {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", 'https://www.baidu.com/', true);

    //发送合适的请求头信息
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xhr.onload = function () {
      // 请求结束后,在此处写处理代码
    };
    xhr.send("foo=bar&type=XMLHttpRequest");
  }
</script>

</html>

展开
收起
游客mcjy2z2syubci 2022-09-30 18:05:11 2379 0
1 条回答
写回答
取消 提交回答
  • 这个人很懒....什么都没写。

    用 axios.js

    2022-10-06 09:37:03
    赞同 1 展开评论 打赏
来源圈子
更多
收录在圈子:
+ 订阅
问答排行榜
最热
最新

相关电子书

更多
钉钉小程序——为工作方式插上翅膀 立即下载
钉钉客户端自动化的应用 立即下载
使命必达 —— 钉钉企业级 消息服务的机遇与挑战 立即下载