亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 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貢獻1829條經驗 獲得超13個贊

我解決了。我只需要使用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),

    });


查看完整回答
反對 回復 2023-03-18
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號