Angular 7 HttpClient发布404

时间:2019-01-27 23:02:42

标签: angular angular7 angular-httpclient

除了在Angular 7应用程序中运行的GET请求外,我似乎什么也没得到。这是代码:

prefix: string = 'assets/data/';

getJsonFile = (fileLocation: string) => {
    return this.http.get(`${this.prefix}${fileLocation}.json`);
};

postJsonFile = (fileLocation: string, data: any) => {
    let headers = new HttpHeaders();
    headers = headers.set('Content-Type', 'application/json');

    let options = { headers: headers };

    return this.http.put(`${this.prefix}${fileLocation}.json`, data, options);
};

fileLocation被传入,而我正在传递相同的字符串“ selling”。 GET成功返回,并且PUT在控制台中引发404(未找到)错误:

PUT http://localhost:4200/assets/data/selling.json 404 (Not Found) scheduleTask @ zone.js:3243
ERROR HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http://localhost:4200/assets/data/selling.json", ok: false, …}

有什么想法吗?预先感谢

0 个答案:

没有答案