我有以下问题:Angular 2 HTTP服务从https切换到http模式
在我从PHP脚本中检索数据的角度服务中,浏览器或角度从https切换到http。我的站点通过HTTPS加载HTS,因此ajax请求被阻止为混合内容。
我已经为我的AJAX服务下面的代码:
import { Injectable, } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class AjaxService {
private apiUrl: string = "https://example.com/myapi/myscript";
/**
* @param {Http} http HTTPService
*/
constructor(private http: Http) { }
/**
* @param {string} piece
*/
public getAllComponents(piece: string) {
console.debug("Get Components for Query: " + piece);
return this.http.get(this.apiUrl + "?compontent=" + piece).map((res: Response) => res.json());
}
[...]
}
当我打电话从https://example.com/Angular2Application
主页我的网页,并触发一个请求,我的浏览器告诉我Ajax请求被阻止混合内容,并告诉我他试图连接到http://example.com/myapi/myscript
我已经尝试这样做了。再试一次,是的...它仍然需要http方案;( –
可能有某种网络服务器重定向呢? – vidalsasoon
不,这真的很奇怪... –