[英]Make request to php endpoint in angular4
所以我是Angular4的新手,我有一个应该向php api发出请求的服务。 我有以下代码-
getWeather(keyword: string){
return this.http.get("weather.php", {
params: new HttpParams().set('keyword', keyword),
headers: new HttpHeaders().set('Method', 'search'),
});
我正在找到404 localhost:4200 / weather.php。 不确定是否要放置php端点文件。
假设localhost:4200是您的前端服务器,则必须在调用中设置php服务器api路径。 如果您的php服务器位于8080端口上的本地,则键入this.http.get('http://localhost:8080/weather.php',...
您可以将其放在src/assets
文件夹中,然后使用this.http.get("assets/weather.php", {...
进行调用。
这是因为Angular应用程序托管在4200端口上,而您的PHP文件将使用端口80。
尝试使用
http://localhot/path/to/weather.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.