Java 错误DOException:无法执行';打开';在';XMLHttpRequest';:无效的URL
我正在使用一个工作正常的数据库,但当我想在表中显示我的信息时,出现了一个错误 我得到以下错误:Java 错误DOException:无法执行';打开';在';XMLHttpRequest';:无效的URL,java,mysql,angular,database,Java,Mysql,Angular,Database,我正在使用一个工作正常的数据库,但当我想在表中显示我的信息时,出现了一个错误 我得到以下错误: ERROR DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL at http://localhost:4200/polyfills.js:6202:31 at XMLHttpRequest.proto.<computed> [as open] (http://localhost:
ERROR DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
at http://localhost:4200/polyfills.js:6202:31
at XMLHttpRequest.proto.<computed> [as open] (http://localhost:4200/polyfills.js:4663:24)
错误DOMEException:未能对“XMLHttpRequest”执行“open”:无效URL
在http://localhost:4200/polyfills.js:6202:31
在XMLHttpRequest.proto。[开放](http://localhost:4200/polyfills.js:4663:24)
我的服务级别:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Certificaten} from "../certificaten";
import {Observable} from "rxjs";
import {environment} from "../../../environments/environment";
@Injectable({
providedIn: 'root'
})
export class CertificatenService {
private certificatenUrl: string;
constructor(private http: HttpClient) {
}
public findAll(): Observable<Certificaten[]> {
return this.http.get<Certificaten[]>(`${environment.CVUrl}certificaten`);
}
public save(certificaten: Certificaten) {
return this.http.post<Certificaten>(this.certificatenUrl, Certificaten);
}
}
从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient,HttpHeaders};
从“./Certificaten”导入{Certificaten};
从“rxjs”导入{observeable};
从“../../../environments/environment”导入{environment};
@注射的({
providedIn:'根'
})
出口级认证服务{
私有证书url:string;
构造函数(专用http:HttpClient){
}
public findAll():可观察{
返回这个.http.get(`${environment.CVUrl}certificaten`);
}
公共存储(certificaten:certificaten){
返回this.http.post(this.certificateUrl,Certificaten);
}
}
感谢您的指导,无需更多 只需要添加几行代码 打开app.moudule.ts文件
import { HttpClientModule } from '@angular/common/http';
imports: [
HttpClientModule
]
就这样,它可以正常工作。您可以检查
环境的值吗。CVUrl
?我认为您错过了http://
或https://
如果您放入任何类似“192.168…”的ip,那么您必须使用
environment.CVUrl='..'希望这将帮助您幸运的是,我已经导入了它。不幸的是,这并没有解决我的问题。谢谢你的回复