【问题标题】:"Http failure response for http://localhost:4200/api/: 404 Not Found" Angular 5“http://localhost:4200/api/ 的 Http 失败响应:404 Not Found” Angular 5
【发布时间】:2018-10-27 18:43:46
【问题描述】:

我从 Angular 5 开始,我想显示来自 JAX-RS API 的城市列表,然后我收到以下错误:

http://localhost:4200/api/ 的 Http 失败响应:404 Not Found

在这里您可以找到我使用的文件:

ville.service.ts

import {Injectable} from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Ville } from '../models/ville.model';


const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

@Injectable()
export class VilleService {

  constructor(private http:HttpClient) {}

    private userUrl = '/api/';

  public getVilles() {
    return this.http.get<Ville[]>(this.userUrl);
  }

  public deleteVille(ville) {
    return this.http.delete(this.userUrl + "/"+ ville.idVille);
  }

  public createVille(ville) {
    return this.http.post<Ville>(this.userUrl, ville);
  }

}

proxy.config.json

{
    "/api/*": {
      "target": "http://localhost:8080/QuickDep/Compagne",
      "secure": false
    }
  }

package.json

"start": "ng serve --proxy-config proxy.config.json",

【问题讨论】:

    标签: angular angular5


    【解决方案1】:

    试试:

    {
        "/api": {
          "target": "http://localhost:8080/QuickDep",
          "secure": false,
          "changeOrigin": true
        }
    }
    

    【讨论】:

    • 私人 userUrl = '/api/';
    • 删除最后一个/
    • 还是一样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多