LoginSignup
12
7

More than 5 years have passed since last update.

GASにPOSTする時はリダイレクトのサポートをオンにするのを忘れるな

Last updated at Posted at 2018-05-14

NodejsでGASにPOSTしようとしたら"Moved Temporarily"というエラーが出ました。

postToGas.js
const rp = require('request-promise');
const formData = { hoge : 'payload'};
rp({
  url : 'https://script.google.com/macros/s/xxx/exec',
  method : 'POST',
  form : formData
})
result.txt
Moved Temporarily
The document has moved 
<A HREF=\"https://script.googleusercontent.com/macros/echo?user_content_key=aaa;lib=bbb\">here</A>

調べてみると request-promise(request) はデフォルトではリダイレクトはフォローされてないようですので、
followAllRedirects をtrueにしたら解決しました。

new_postToGas.js
const rp = require('request-promise');
const formData = { hoge : 'payload'};
rp({
  url : 'https://script.google.com/macros/s/xxx/exec',
  method : 'POST',
  form : formData,
  followAllRedirects : true
})
//これで正常にPOSTされます

12
7
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
12
7