首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >http://localhost:4200/api/auth.php 404 (未找到)

http://localhost:4200/api/auth.php 404 (未找到)
EN

Stack Overflow用户
提问于 2018-06-30 15:06:09
回答 1查看 832关注 0票数 -2

app.module.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
{ "/api": { "target": "http://localhost/test/api/auth.php", "secure": false, "changeOrigin": true

}
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-02 01:02:52

我遵循了本教程,遇到了同样的问题,我不得不将此代码添加到auth.php文件的开头;

代码语言:javascript
复制
header('Access-Control-Allow-Origin: *'); 
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, 
Accept");

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

代码语言:javascript
复制
<?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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51112592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档