我正在使用Loopback Connector REST(1.9.0)并有一个返回XML的远程方法:
Foo.remoteMethod
(
"getXml",
{
accepts: [
{arg: 'id', type: 'string', required: true }
],
http: {path: '/:id/content', "verb": 'get'},
returns: {"type": "string", root:true},
rest: {"after": setContentType("text/xml") }
}
)
Run Code Online (Sandbox Code Playgroud)
响应始终返回转义的JSON字符串:
"<foo xmlns=\"bar\"/>"
Run Code Online (Sandbox Code Playgroud)
代替
<foo xmlns="bar"/>
Run Code Online (Sandbox Code Playgroud)
请注意,响应的内容类型设置为text/xml.
如果我将Accept:标题设置为"text/xml",我总是将"Not Acceptable"作为响应.
如果我订
"rest": {
"normalizeHttpPath": false,
"xml": true
}
Run Code Online (Sandbox Code Playgroud)
在config.json中,然后我得到500错误:
SyntaxError: Unexpected token <
Run Code Online (Sandbox Code Playgroud)
我认为"xml:true"属性只是导致响应解析器尝试将JSON转换为XML.
如何在不解析的情况下让Loopback返回响应中的XML?问题是我将返回类型设置为"string"?如果是这样,Loopback会识别为XML的类型是什么?