【发布时间】:2019-01-30 08:34:46
【问题描述】:
我正在尝试使用带有 xml 响应的 http RSS 服务。
我得到响应状态 OK(200) 并出现以下错误:
在 XMLHttpRequest.onLoad 的 JSON.parse() 的位置 0 处的 JSON 中的意外标记
我做错了什么,如何解析 xml 响应?
Component.ts 代码:
this.ns.nBasicApi().subscribe((jsonFromServer) => {
this.response = jsonFromServer;
});
服务代码:
nBasicApi():any {
return this.http.get('http://localhost:3000/api/stocks');
}
服务器代码 App.js:
const fetch = require('isomorphic-fetch');
const express = require('express');
const app = express();
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods',
'GET,POST,OPTIONS,DELETE,PUT');
res.header('Access-Control-Allow-Headers','Accept,Accept-
Language,Content-Language,Content-Type');
res.header('Access-Control-Expose-Headers','Content-
Length,Content-Range');
next();
})
app.route('/api/stocks').get((req, res) => {
fetch('http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?
data=quotes&symbol=NFLX').then((res) => {
return res.text();
}).then((json) => {
res.send(json)
})
});
【问题讨论】:
标签: xml angular http service rss