角度从帖子请求中删除基本网址

时间:2017-12-03 22:15:00

标签: angular

我在Angular 4中有以下服务,当我尝试将信息发布到我的服务器时,它会对我的请求应用“http://localhost:4200”,结果为“http://localhost:4200/localhost:5000/login”。我怎么解决这个问题?

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


@Injectable()
export class AuthService {

  constructor(private http: HttpClient) { }

  public authFunc(payload) {
    const headers = new HttpHeaders();
    headers.set('Content-Type', 'application/json');
    console.log(this.http.post);

    return this.http.post("http:/localhost:5000/login", payload, {headers: headers});
  }
}

1 个答案:

答案 0 :(得分:0)

return this.http.post("/login", payload, {headers: headers});

编辑:您是否在端口5000上运行了Web服务器?