因此,我的应用由一个简单的Web服务器提供服务,位于“ https:// localhost:8443 / app ”下,而同一个Web服务器在例如处返回json响应。“ https:// localhost:8443 / api / login ”。
TLS现已使用自签名证书设置。
当我请求该应用程序时,我收到证书警告,该警告将被跳过,然后我看到我的登录页面。
单击登录按钮后,Angular应用程序将执行
http.post<LoginResponse>('/api/login', body)
Run Code Online (Sandbox Code Playgroud)
它作为对“ http:// localhost:8443 / api / login ” 的发布请求显示在我的浏览器网络跟踪中。
我找不到任何有关此的信息,只有有关在使用angular-cli运行应用程序时如何处理tls的信息。
为什么该应用程序默认为http,我在哪里告诉它使用https?
小智 6
在 Angular文档中,他们有一个使用拦截器来确保 https 的示例。下面的代码片段取自他们的文档:
// clone request and replace 'http://' with 'https://' at the same time
const secureReq = req.clone({
url: req.url.replace('http://', 'https://')
});
// send the cloned, "secure" request to the next handler.
return next.handle(secureReq);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2819 次 |
| 最近记录: |