[英]Angular 2 HTTP Service switch from https to http scheme
我有以下問題:
在我的從PHP腳本檢索數據的角度服務中,瀏覽器或角度從https切換到http。 我的網站通過HTS通過HTTPS加載,因此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
僅提供不帶方案的網址。 例如:
private apiUrl: string = "//example.com/myapi/myscript";
您的瀏覽器將與當前頁面的方案匹配,從而避免出現混合內容問題。
現在可以了。 沒有計划為什么,但是還可以。
關閉
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.