Guy*_*Guy 11 json google-apps-script
我正在尝试POST一个期望使用Google Apps脚本获取JSON作为有效负载的Web服务.我正在使用以下代码:
var options =
{
"method" : "post",
"contentType" : "application/json",
"headers" : {
"Authorization" : "Basic <Base64 of user:password>"
},
"payload" : { "endDate": "2012-06-03" }
};
var response = UrlFetchApp.fetch("http://www.example.com/service/expecting/json", options);
Run Code Online (Sandbox Code Playgroud)
在服务器端,我收到以下错误:
WARN [facade.SettingsServlet] 04 Jun 2012 15:30:26 - Unable to parse request body: endDate=2012-06-03
net.liftweb.json.JsonParser$ParseException: unknown token e
Run Code Online (Sandbox Code Playgroud)
我假设服务器期待得到
{ "endDate": "2012-06-03" }
Run Code Online (Sandbox Code Playgroud)
代替
endDate=2012-06-03
Run Code Online (Sandbox Code Playgroud)
但我不知道如何让UrlFetchApp做到这一点.
Thi*_*ard 14
我不理解服务器端错误,但'payload'参数必须是此处指定的字符串:https://developers.google.com/apps-script/class_urlfetchapp?hl = fr-FR #fetch.
尝试:
var options =
{
"method" : "post",
"contentType" : "application/json",
"headers" : {
"Authorization" : "Basic <Base64 of user:password>"
},
"payload" : '{ "endDate": "2012-06-03" }'
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17646 次 |
| 最近记录: |