簡體   English   中英

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

[英]How to keep line breaks in POST message

當我得到 email 的內容時,它的格式是換行符,但是當我將它發送到 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),
    });
  }

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM