如何通过urlfetchapp向有效载荷中的数组发送发布请求 [英] How to send a post request with an array in payload by urlfetchapp

查看:116
本文介绍了如何通过urlfetchapp向有效载荷中的数组发送发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要模拟从HTML表单到页面的发布请求。我需要知道,如何在有效载荷中正确发送数组。感谢您提前致谢。

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..

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

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"
  }
}

我有在GAS中编写代码,它应该模拟相同的请求:

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",

应该有这个代替:

  "form": {
    "Link[]": [
      "picturelink1.png", 
      "picturelink2.png", 
      "picturelink3.png"
    ], 

我也尝试将其串化并以JSON形式发送

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任何帮助..

thx for any help..

推荐答案

它!!! haleluya ..
有效载荷必须以这种方式准备!我在制作解决方法PHP脚本期间找到了这个解决方案。

I have found it!!! haleluya.. the payload has to be prepared in this way! I have found this solution during I was making a workaround PHP script.

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

不太直观,但效果很好!

Not very intuitive, but it works great!

收到的有效内容看起来不像HTML表单,但在我的情况下它工作正常!

Received payload doesnt look like the same like from a HTML form, but in my case it worked!

{ "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": "" }, .....

这篇关于如何通过urlfetchapp向有效载荷中的数组发送发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆