8
5

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 5 years have passed since last update.

curl→gsに変換

Posted at

GAS触ってる人からしたら常識ですが...

gsとはgoogle apps scriptで動くjsみたいな言語のこと。
例をあげます。

curl

curl -X POST 'http://localhost:3000/test' \
-H "Accept: application/json" -H "Content-type: application/json" \
-d '{"array":["59","33"],"date":"15 May 2018 00:00:00 GMT","id":"71"}'

gs

var url = "http://localhost:3000/test";

var headers = {
  "Accept": "application/json",
  "Content-type": "application/json"
}

var data = {
  "array":["59","33"],
  "date":"15 May 2018 00:00:00 GMT",
  "id":"71"
}

var options = {
  "method": "post",
  "payload": JSON.stringify(data),
  "headers": headers
};
UrlFetchApp.fetch(url, options);

実際にはgasからlocalhostに飛ばせないですけど(多分)、例として...

optionsのpayloadはstringにしないとうまく渡らないこと多いです。
特にjsonのなかに配列とかのobjectがある場合は。
API側の仕様次第ですが。

8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?