目前我在移动和网站上使用HTTPS构建了API服务器 . 端口8100的前端移动(离子网/移动)正在使用API HTTPS . 但是当使用端口9999的角度网络时,API HTTPS不能很好地工作,但是在localhost:8888上运行API服务器就像魅力一样 .

ExpressJS

var cors = require('cors');
var http = require('http');
var app = express();
var server = http.createServer(app);
var port = process.env.PORT || 3000; // Always running at port 8888
app.use(cors());

Request Header

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8
Authorization: (Some long string here)
Cache-Control:max-age=0
Connection:keep-alive
Host: api.web.com
Origin: http://localhost:9999

Problem

在用户授权之前,我没有使用POST API到服务器的问题 . 在Authorization标头上存储访问令牌并指向仪表板后,API调用的每个方法(GET,PUT,POST)都会返回400 BAD REQUEST . 请求的资源上不存在“Access-Control-Allow-Origin”标头 . 因此不允许来源'http:// localhost:9999'访问 . 响应具有HTTP状态代码400 .