我正在尝试运行我的 Angular 2 应用程序,一切都进行得相对顺利,直到我使用 API 获取一些数据。
当 Angular 的 http 模块执行该 OPTIONS 请求时,Apache 将以 301 重定向进行响应,请参阅标头:
要求:
OPTIONS http://api.mydomain.com/register/
Host: api.mydomain.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Origin: http://app.mydomain.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
回复:
Connection: Keep-Alive
Content-Length: 341
Content-Type: text/html; charset=iso-8859-1
Date: Wed, 18 May 2016 18:35:02 GMT
Keep-Alive: timeout=5, max=100
Location: http://api.mydomain.com/register
Server: Apache/2.4.7 (Ubuntu)
老实说,我对 Angular 和 CORS 还不熟悉,所以我希望我只是犯了一个新手错误。谢谢你的帮助!