Last active
April 19, 2019 20:41
-
-
Save yehara/9337761 to your computer and use it in GitHub Desktop.
Google Apps Script で multipart/form-data の HTTP リクエストを送信する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function request() { | |
var parts = []; | |
parts.push({name: "processModelInfoId", value: 1}); | |
parts.push({name: "nodeNumber", value: 1}); | |
parts.push({name: "key", value: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}); | |
parts.push({name: "title", value: "件名をここに"}); | |
parts.push({name: "data[0].upload", value: "ファイル本文をここに", filename: "ファイル名.csv", contentType: "text/csv; charset=UTF-8"}); | |
var boundary = "boundaryboundaryboundaryboundary"; | |
var payload = ""; | |
if (parts.length > 0) { | |
for (var i=0; i<parts.length; i++) { | |
payload += "--" + boundary + "\r\n"; | |
if (parts[i].filename !== undefined) { | |
payload += "Content-Disposition: form-data; name=\"" + parts[i].name + "\"; filename=\"" + parts[i].filename + "\"\r\n"; | |
payload += "Content-Type: " + parts[i].contentType + "\r\n"; | |
payload += "\r\n" | |
payload += parts[i].value + "\r\n"; | |
} else { | |
payload += "Content-Disposition: form-data; name=\"" + parts[i].name + "\"\r\n"; | |
payload += "\r\n" | |
payload += parts[i].value + "\r\n"; | |
} | |
} | |
payload += "--" + boundary + "--\r\n" | |
} | |
var options = { | |
"method" : "post", | |
"contentType" : "multipart/form-data, boundary=" + boundary, | |
"payload" : payload | |
}; | |
UrlFetchApp.fetch("https://YYYYYYYYY.questetra.net/System/Event/MessageStart/start", options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very useful script, thanks!