0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Node-REDでraw bodyが取りたい!

Last updated at Posted at 2020-05-07

はじめに

http requestを受け取る際にNode-REDは気が利く奴なので
整形したbody情報を渡してくれます。😇
また、raw bodyの情報は見えません。
メモリを食わないように気を使ってくれています。😍
でも、たまにraw bodyを取得したい。。

raw bodyを取得する。

多分、以下でraw bodyを取れます。(取れてるはず..)

encodeURIComponent(JSON.stringify(msg.payload))

RFC3986に忠実に変換する場合encodeURIComponentを以下に変更

function fixedEncodeURIComponent (str) {
  return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16);
  });
}

RFC1738

function rawurlencode (str) {
  return encodeURIComponent(str)
    .replace(/!/g, '%21')
    .replace(/'/g, '%27')
    .replace(/\(/g, '%28')
    .replace(/\)/g, '%29')
    .replace(/\*/g, '%2A')
}

let requestBody = rawurlencode(msg.payload);

最後に

間違ってたら教えて下さい🙇

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?