第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

JS HTTP 后 YAML

JS HTTP 后 YAML

達令說 2023-05-11 14:28:01
我無法在 js 中通過 http 發(fā)布 yaml。當我對正文使用 JSON.stringify(text) 并具有內(nèi)容類型 application/json 時,代碼有效。如果我使用 YAML stringify,服務器端的正文只是 {}。我有 areatext,我在 html 中輸入文本(如 yaml 格式),例如martin:  name: Martin D'vloper  job: Developer  skill: Elite客戶:$('#create-yaml2').on('click',async function () {    var text = $('#yaml-create').val();    // console.log(text)    var textYAML = YAML.stringify(text);    var options = {      hostname: 'myhostname',      port: 80,      path: `/api/postyaml`,      method: 'POST',      body: textYAML,      headers: {        'Content-Type': 'text/x-yaml'      }    };    var executeReq = http.request(options);    executeReq.write(textYAML);    executeReq.end();  });編輯:服務器端的功能,在發(fā)布 JSON 時打印非空 {}。exports.functionCalled = async function (req, res) {    console.log('\n\n\n\n')    console.log(req.body)    console.log('\n\n\n\n')    try {        res.send(`RECEIVED`);      } catch (upgradeErr) {        res.status(422).json({          message: `Failed`,          error: upgradeErr        });    }}
查看完整描述

2 回答

?
慕尼黑5688855

TA貢獻1848條經(jīng)驗 獲得超2個贊

您已經(jīng)有一個來自 HTML 的字符串,因此您不需要YAML.stringify再次調用 - 文本已經(jīng)是一個字符串。


$('#create-yaml2').on('click',async function () {

    var text = $('#yaml-create').val();

    // console.log(text)

    var textYAML = text;

    var options = {

      hostname: 'myhostname',

      port: 80,

      path: `/api/postyaml`,

      method: 'POST',

      body: textYAML,

      headers: {

        'Content-Type': 'text/x-yaml'

      }

    };

    var executeReq = http.request(options);

    executeReq.write(textYAML);

    executeReq.end();

  });

你可能想做類似的事情


$('#create-yaml2').on('click',async function () {

    var text = $('#yaml-create').val();

try {

  YAML.parse(text)

} catch(e) {...}


...

send request


確保提供了有效的 YAML


查看完整回答
反對 回復 2023-05-11
?
萬千封印

TA貢獻1891條經(jīng)驗 獲得超3個贊

YAML.stringify將 JavaScript 數(shù)據(jù)結構轉換為包含 YML 的字符串。

你沒有 JavaScript 數(shù)據(jù)結構,你只是一個包含 YML 的字符串。

幾乎。你有一個錯誤。您不能'在未加引號的 YML 字符串中使用 raw。

所以:

修復你的 YML:

martin: 
 name: "Martin D'vloper"
  job: Developer
  skill: Elite

不要對其進行雙重編碼:

var textYAML = $('#yaml-create').val();


查看完整回答
反對 回復 2023-05-11
  • 2 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號