Kea*_*nge 4 javascript json azure node.js azure-functions
我有一个使用此源的azure功能设置:
module.exports = function(context, req) {
//this is the entire source, seriously
context.done(null, {favoriteNumber : 3});
};
Run Code Online (Sandbox Code Playgroud)
当我使用像postman这样的工具来访问它时,我得到一个不错的JSON输出,就像我想要的那样:
{
"favoriteNumber": 3
}
Run Code Online (Sandbox Code Playgroud)
问题是当我在浏览器(chrome,firefox等)中访问它时,我看到:
<ArrayOfKeyValueOfstringanyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><KeyValueOfstringanyType><Key>favoriteNumber</Key><Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:int">3</Value></KeyValueOfstringanyType></ArrayOfKeyValueOfstringanyType>
Run Code Online (Sandbox Code Playgroud)
您是否尝试将响应对象Content-Type明确设置为application\json?
module.exports = function(context, req) {
res = {
body: { favoriteNumber : 3},
headers: {
'Content-Type': 'application/json'
}
};
context.done(null, res);
};
Run Code Online (Sandbox Code Playgroud)
默认情况下,为内容协商配置功能.当您呼叫您的功能时,Chrome会发送一个标题
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Run Code Online (Sandbox Code Playgroud)
所以,它要求XML并将其取回.
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |