2016-10-03 72 views
0

我有一個通過https協議提供的網站。這是用angularJs編寫的。該網站呼籲通過HTTP一個asp.net的Web API服務,然後我得到這個錯誤:如何從https網站調用web api?

angular.js:10765 Mixed Content: The page at ' https://example.com/forms/#/question-set-4#topOfThePage ' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ' http://webapiaddress/api/ControllerName/GenerateCaptcha '. This request has been blocked; the content must be served over HTTPS.(anonymous function) @ angular.js:10765r @ angular.js:10558g @ angular.js:10268(anonymous function) @ angular.js:14792$eval @ angular.js:16052$digest @ angular.js:15870$apply @ angular.js:16160g @ angular.js:10589T @ angular.js:10787w.onload @ angular.js:10728 angular.js:10765 XMLHttpRequest cannot load http://webapiaddres/api/SomeController/GenerateCaptcha . Failed to start loading.

所以錯誤,我認爲,我應該服務於網頁API自主機通過HTTPS ADDRES。所以在這個網頁API自主機我將其更改爲https // webapiaddres/

的配置但後來我發現了這一點:

angular.js:10765 GET https:/webapiaddress/api/SomeController/GenerateCaptcha net::ERR_INSECURE_RESPONSE

我在做什麼錯?這是爲什麼發生。奇怪的是,這並沒有尖叫,我沒有啓用CORS,但這可能是因爲這個web api selfhost和站點在同一臺服務器上。我無法在Google中找到任何類似的問題。

+0

[在訪問chrome net :: ERR \ _INSECURE \ _RESPONSE中訪問localhost api時出現錯誤(http://stackoverflow.com/questions/24598187/error-when-accessing-localhost-api-in-chrome- neterr-insecure-response) – Matheno

+0

對不起,但我不認爲這是它。從該帖子看來,有人試圖通過https調用服務,這是通過https協議提供的。我的問題是相反的 –

回答

0

我設法解決了我的同事的問題,它非常簡單。它一眼就看不出來了。我已經在chrome瀏覽器中運行了web api的地址,並且有請求接受證書。當我這樣做時,一切順利。這不是來自代碼的管理員工作,但這是相當有趣的體驗。