http://localhost:4200/api/auth.php 404 (Not Found)



app.module.ts

import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Headers, Http } from '@angular/http';
@Injectable({ providedIn: 'root' }) export class AuthService {
constructor(private http: HttpClient) { }
getUserDetails(username, password){ return this.http.post('/api/auth.php',{ username, password }).subscribe(data => { console.log(data, "Is what we got from the server"); }) } }

proxyconfig.json

{ "/api": { "target": "http://localhost/test/api/auth.php", "secure": false, "changeOrigin": true
}
}

我正在按照本教程进行操作并遇到同样的问题,我不得不将此代码添加到 auth.php 文件的开头;

header('Access-Control-Allow-Origin: *'); 
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, 
Accept");

所以前五行现在看起来像;

<?php
header('Access-Control-Allow-Origin: *'); 
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, 
Accept");
session_start();
$_POST = json_decode(file_get_contents('php://input'), true);

最新更新