I need to simulate post request from a html Form to a page. I need to know, how to properly send an array in payload. Thanks in advance..
I have easy html code which will be on submit received by target page in this way:
{
"args": {},
"data": "",
"files": {},
"form": {
"Link[]": [
"picturelink1.png",
"picturelink2.png",
"picturelink3.png"
],
"animationtype": "link",
"size": "400",
"speed": "0.4",
"usersize": "",
"userspeed": "0.1"
}
}
I have written code in GAS, which should simulate the same request:
var payload =
{
"Link[]":["jovianarchive_com/Content/Charts/621903744000000000_png","jovianarchive_com/Content/Charts/621903708000000000_png","jovianarchive_com/Content/Charts/621903816000000000_png"],
"animationtype":"link","size":"300","speed":"1","usersize":"","userspeed":""
}
var options =
{
"method" : "post",
"payload" : payload
};
var result = (UrlFetchApp.fetch("http://httpbin.org/post", options).getContentText());
and this returns this request:
{
"args": {},
"data": "",
"files": {},
"form": { "Link[]": "[Ljava.lang.Object;@536733f2",
"animationtype": "link",
"size": "300",
"speed": "1",
"usersize": "",
"userspeed": ""
}
The problem is here:
"form": { "Link[]": "[Ljava.lang.Object;@536733f2",
there should be this instead:
"form": {
"Link[]": [
"picturelink1.png",
"picturelink2.png",
"picturelink3.png"
],
I have also tried to stringify it and send as JSON
"Content-type" : "application/json",
but it not produces desired output neither..
It receives payload as quoted string:
"args": {}, "data": "", "files": {}, "form": { "{\"Link[]\":[\"jovianarchive_com/Content/Charts/621903744000000000_png\",\"jovianarchive_com/Content/Charts/621903708000000000_png\",\"jovianarchive_com/Content/Charts/621903816000000000_png\"],\"animationtype\":\"link\",\"size\":\"300\",\"speed\":\"1\",\"usersize\":\"\",\"userspeed\":\"\"}": "" }, .....
thx for any help..