2016-10-03 69 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的地址,并且有请求接受证书。当我这样做时,一切顺利。这不是来自代码的管理员工作,但这是相当有趣的体验。