0
我需要模擬從HTML表單到頁面的發佈請求。我需要知道,如何在有效載荷中正確發送數組。在此先感謝..如何發送郵件請求與有效載荷中的數組通過urlfetchapp
我有這將在提交的目標頁面以這種方式獲得簡單的HTML代碼:氣體
{
"args": {},
"data": "",
"files": {},
"form": {
"Link[]": [
"picturelink1.png",
"picturelink2.png",
"picturelink3.png"
],
"animationtype": "link",
"size": "400",
"speed": "0.4",
"usersize": "",
"userspeed": "0.1"
}
}
我寫的代碼,這應該模擬了同樣的要求:
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());
,這將返回這個請求:
{
"args": {},
"data": "",
"files": {},
"form": { "Link[]": "[Ljava.lang.Object;@536733f2",
"animationtype": "link",
"size": "300",
"speed": "1",
"usersize": "",
"userspeed": ""
}
的問題是在這裏:
"form": { "Link[]": "[Ljava.lang.Object;@536733f2",
應該有這個代替:
"form": {
"Link[]": [
"picturelink1.png",
"picturelink2.png",
"picturelink3.png"
],
我也試圖字符串化它,併發送爲JSON
"Content-type" : "application/json",
,但它不產生所需的輸出既不..
它接收有效載荷作爲報價字符串:
"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對於任何幫助..
說明:你是否試圖發送「application/x-www-form-urlencoded」數據? – Karan
我試圖發送一個有3個字符串的數組.. 即: var payload = { 「Link []」:[「http://jovianarchive.com/Content/Charts/621903744000000000_.png」,「 http://jovianarchive.com/Content/Charts/621903708000000000_.png"," http://jovianarchive.com/Content/Charts/621903816000000000_.png「], 」animationtype「:」link「,」size「:」 300「,」速度「:」1「,」usersize「:」「,」userspeed「:」「 } –
不會JSON爲你工作嗎?這樣你可以很容易地使用{「Link」:[「file1.png」,「file2.png」,「file3.png」]} 你只需要將「Content-type」設置爲「application/json」,然後你可以在對象上使用JSON.stringify。 – Karan