gpt4 book ai didi

google-apps-script - 如何通过 urlfetchapp 在有效负载中发送带有数组的发布请求

转载 作者:行者123 更新时间:2023-12-04 13:48:28 26 4
gpt4 key购买 nike

我需要模拟从 html 表单到页面的 post 请求。我需要知道,如何在有效负载中正确发送数组。提前致谢..

我有简单的 html 代码,它将以这种方式提交给目标页面:

{
"args": {},
"data": "",
"files": {},
"form": {
"Link[]": [
"picturelink1.png",
"picturelink2.png",
"picturelink3.png"
],
"animationtype": "link",
"size": "400",
"speed": "0.4",
"usersize": "",
"userspeed": "0.1"
}
}

我在 GAS 中编写了代码,它应该模拟相同的请求:
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\":\"\"}": "" }, .....

感谢您的帮助。

最佳答案

我找到了!!!哈路亚..
必须以这种方式准备有效载荷!我在制作 PHP 脚本时找到了这个解决方案。

  var payload =
{
"Link[0]":"http://..",
"Link[1]":"http://..",
"animationtype":"link","size":"300","speed":"1","usersize":"","userspeed":""
}...

不是很直观,但效果很好!

接收到的有效载荷与 HTML 表单中的不同,但在我的情况下它起作用了!
{ "args": {}, "data": "", "files": {}, "form": 
{
"Link[0]": "http://jovianarchive.com/Content/Charts/621903744000000000_.png",
"Link[1]": "http://jovianarchive.com/Content/Charts/621903708000000000_.png",
"animationtype": "link", "size": "300", "speed": "1", "usersize":` "","userspeed": "" }, .....

关于google-apps-script - 如何通过 urlfetchapp 在有效负载中发送带有数组的发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com