从服务器本地主机Apache mysql请求问题

时间:2018-12-20 17:36:13

标签: php http localhost

向本地服务器发送HTTP POST请求时遇到问题。这些是我得到的错误:

POST http://XXX.X.X.X:3306/login.php net::ERR_INVALID_HTTP_RESPONSE

HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
message: "Http failure response for (unknown url): 0 Unknown Error

我认为这与URL有关。当我在本地浏览器上打开login.php文件时,似乎没有任何问题,因此使我觉得这可能是URL的端口不正确。

这是我发送POST请求的打字稿代码:

private getloginURL = "http://XXX.X.X.X:3306/login.php";
// methods
  logIn(username: string, password: string) {
    let sendData = new FormData();
    sendData.append('username', username);
    sendData.append('password', password);


    this.http.post(this.getloginURL, sendData, {responseType: 'text'}).subscribe(data=> {
        console.log(data);
        this.currLoginStatus.next(data); // pushing data into behavior subject
    });

如何找到本地服务器的正确URL?我正在使用Apache和mySQL。谢谢!

编辑:

对于端口80,这些是我得到的错误:

POST http://127.0.0.1/login.php 404 (Not Found)

Access to XMLHttpRequest at 'http://127.0.0.1/login.php' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
message: "Http failure response for (unknown url): 0 Unknown Error

对于端口443,与以前使用端口3306时出现的错误相同。

0 个答案:

没有答案