更新时间:2025-01-07 gmt 08:00
使用apig触发器调用一个返回string的functiongraph函数时,报500错误-j9九游会登录
functiongraph函数对来自apig调用的返回结果进行了封装,apig触发器要求函数的返回结果中必须包含body(string)、statuscode(int)、headers(map)和isbase64encoded(boolean),才可以正确返回。
node.js函数apig触发器调用返回结果定义示例如下:
exports.handler = function (event, context, callback) {
const response = {
'statuscode': 200,
'isbase64encoded': false,
'headers': {
"content-type": "application/json"
},
'body': 'hello, functiongraph with apig',
}
callback(null, response);
}
java函数apig触发器调用返回结果定义示例如下:
import java.util.map;
public httptriggerresponse index(string event, context context){
string body = "functionstage "
"
"
"this is a simple apig trigger test
"
"this is a simple apig trigger test
"
"";
int code = 200;
boolean isbase64 = false;
map headers = new hashmap();
headers.put("content-type", "text/html; charset=utf-8");
return new httptriggerresponse(body, headers, code, isbase64);
}
class httptriggerresponse {
private string body;
private map headers;
private int statuscode;
private boolean isbase64encoded;
public httptriggerresponse(string body, map headers, int statuscode, boolean isbase64encoded){
this.body = body;
this.headers = headers;
this.statuscode = statuscode;
this.isbase64encoded = isbase64encoded;
}
}
父主题: 调用函数
相关文档
意见反馈
文档内容是否对您有帮助?
提交成功!非常感谢您的反馈,我们会继续努力做到更好!
您可在查看反馈及问题处理状态。
系统繁忙,请稍后重试
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨