首页 > 解决方案 > 内容类型:application/x-www-form-urlencoded 在 Angular 6 中不起作用

问题描述

尝试使用 url 中编码的数据发送请求。为此使用 Angular 6,HttpClient。

private url = "http://localhost/login.php";
private httpOptions = {
    headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' })
};

constructor(private http: HttpClient){}

login(email: string, password: string){
    return this.http.post(this.url, {username: email, password: password}, this.httpOptions);
}

据我了解,“内容类型”应该对此进行编码:

{username: email, password: password}

进入这个:

username=email&password=password

当然是价值观。

但在我的情况下,URL 编码的表单数据是相同的(开发工具结果):

{"username":"eee@eee.com","password":"eeee"}: 

你能告诉我这怎么可能得到一个正常的结果?由于这个,不能简单地 $_POST'ed 后端。

标签: angularhttp-headers

解决方案


推荐阅读