概要
NodejsのrequestモジュールからGoogle Apps Script(GAS)のウェブアプリケーションにPOSTする際に、Moved Temporarilyとなり期待したPOSTとならない時の対処方法について紹介します
対処方法
requestのoptionにfollowAllRedirectsプロパティを追加することでリクエスト先でのリダイレクトを許可してあげることで期待した処理が得られる
const request = require('request');
const payload = {
param1: 'param1',
param2: 'param2'
};
const option = {
uri: '<google apps script endpoint>',
headers: {
'Content-type': 'application/json'
},
json: true,
followAllRedirects: true,
form: payload
};
request.post(option, function(err, resp, body) {
console.log(body);
});