为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 POST 消息中保留换行符

如何在 POST 消息中保留换行符

慕村225694 2023-03-18 16:51:15

当我收到一封电子邮件的内容时,它的格式是换行符,但当我将它发送到 API 时,结果是没有空格的文本。


有什么办法可以保持间距?


编辑:


const postNewTask = (taskTitle, taskComment, workerId) => {

  const { projectId, tasklistId } = dataStore();


  const { userEmail, apiKey } = credentialsStore();


  const options = {

    method: 'POST',

    headers: {

      Authorization:

        'Basic ' + Utilities.base64Encode(`${userEmail}:${apiKey}`),

    },

  };


  if (taskComment && workerId) {

    options.payload = JSON.stringify({

      name: taskTitle,

      comment: {

        content: taskComment,

      },

      worker: parseInt(workerId),

    });

  }


查看完整描述

1 回答

?
烙印99

TA贡献1602条经验 获得超12个赞

我解决了。我只需要使用taskComment.replace(/(?:\r\n|\r|\n)/g, '<br>'),API 就知道该怎么做。


最终工作代码:


const postNewTask = (taskTitle, taskComment, workerId) => {

  const { projectId, tasklistId } = dataStore();


  const { userEmail, apiKey } = credentialsStore();


  const options = {

    method: 'POST',

    headers: {

      Authorization:

        'Basic ' + Utilities.base64Encode(`${userEmail}:${apiKey}`),

    },

  };


  if (taskComment && workerId) {

    options.payload = JSON.stringify({

      name: taskTitle,

      comment: {

        content: taskComment.replace(/(?:\r\n|\r|\n)/g, '<br>'),

      },

      worker: parseInt(workerId),

    });


查看完整回答
反对 回复 2天前
  • 1 回答
  • 0 关注
  • 6 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信