角4:“对(未知URL):0未知错误的Http失败响应”; [英] Angular 4: "Http failure response for (unknown URL): 0 Unknown Error"
问题描述
我正在尝试使用API URL。我正在使用以下代码调用API。
I am trying to consume an API URL. I am calling the API with the below code.
import {HttpClient, HttpClientModule, HttpParams} from "@angular/common/http";
@Injectable()
export class PropertyPrefService {
constructor(private http: HttpClient,
private configurationService:Configuration) {}
public searchProjects(propFilter:string):any{
let temp:any;
const options = propFilter ?
{
params: new HttpParams().set('query', propFilter)
} : {};
return this.http.get<any>(this.configurationService.propertySystemApiUrl, options)
.subscribe((results:any) => {
console.log(results);
});
}
在Angular代码中,我没有得到任何响应,并且得到了一个错误:
In the Angular code I am not getting any response and am getting an error:
(未知网址)的HTTP失败响应:0未知错误。
Http failure response for (unknown url): 0 Unknown Error".
但是,当我在Chrome上打开开发人员工具时发出请求时,我看到从服务器收到了响应。
However, when I make a request if I open up developer tools on Chrome, I see that the response is received from the server.
URL是 https:// ... URL,而不是 http:// ...。
The URL is the "https://..." URL and not "http://...".
推荐答案
问题是Angular Universal使用Express,并且安全性验证了服务器的SSL证书;我使用了自签名SSL证书。
The problem is Angular Universal used Express, and the security validates the SSL certificate to the server; I used a self-signed SSL certificate.
解决方案是添加 NODE_TLS_REJECT_UNAUTHORIZED = 0
添加到您的环境以禁用Node.js中的SSL验证。您应该仅在开发中进行设置;在生产中这非常危险
The solution is to add NODE_TLS_REJECT_UNAUTHORIZED=0
to your environment to disable the SSL verification in Node.js. You should only set this in development; in production it is very risky.
这篇关于角4:“对(未知URL):0未知错误的Http失败响应”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!