Azure Functions Redirect Header(Azure Functions 重定向标头)
问题描述
我希望我的一个 Azure Functions 执行 HTTP 重定向.
I want one of my Azure Functions to do an HTTP Redirection.
这是函数的当前代码:
module.exports = context => {
context.res.status(302)
context.res.header('Location', 'https://www.stackoverflow.com')
context.done()
}
但它不起作用.
从 Postman 发送的请求显示响应有:
A request sent from Postman shows the response has:
状态:200位置未设置
Status: 200Locationnot set
这是正确的代码吗?还是 Azure Functions 根本不允许?
Is this correct code? Or is it simply not allowed by Azure Functions?
推荐答案
上面的代码确实有效,除非您将绑定名称设置为 $return,这就是我假设您现在拥有的(您可以在集成标签)
The code above actually does work, unless you have your binding name set to $return, which is what I assume you have now (you can check in the integrate tab)
以下任一选项也可以满足您的需求
Either of the following options will also do what you're looking for
假设 $return 在绑定配置中:
Assuming $return in the binding configuration:
module.exports = function (context, req) {
var res = { status: 302, headers: { "location": "https://www.stackoverflow.com" }, body: null};
context.done(null, res);
};
或者使用express style"API(在绑定配置中不使用$return):
Or using the "express style" API (not using $return in the binding configuration):
module.exports = function (context, req) {
context.res.status(302)
.set('location','https://www.stackoverflow.com')
.send();
};
这篇关于Azure Functions 重定向标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure Functions 重定向标头
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
