LoginSignup
0
0

More than 5 years have passed since last update.

nodeでPOST RequestするときにURL encodeで投げてしまった。

Posted at

lambdaで自作のPOST APIを叩こうとしたらうまくいかなかった。
結論から言えば、APIとしてはJSONのbodyしか対応していないのにurlencodeされたRequestを投げていた。
その備忘録

JSONは

{ 
 "key1":"value1",
 "key2":"value2"
}

こんな感じなのだが、受け側で勝手に

key1=value1&key=value2

みたいになってしまいJSON Parseのエラーを吐いていた。

Request側で

let RequestJson =
{ 
 "key1":"value1",
 "key2":"value2"
};

としたとき


let reqBody = JSON.stringify(RequestJson);

としなければならないのに


let reqBody = querystring.stringify(RequestJson);

としていたようだ。
初歩的ミスすぎて気づくのに無駄に時間がかかってしまった。

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