angular - 内容类型: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 后端。
解决方案
推荐阅读
- node.js - 如何使用 NodeJS 以间隔发出 API 请求
- javascript - 使用 Javascript 中的选择框搜索和过滤结果
- django - django 视图部分中的代码混淆
- kubernetes - Flink Statefun HA Kubernetes 集群
- c++ - 如何强制编译器在寄存器中生成关键变量?
- qt - 很想在小部件上隐藏此按钮?
- c - Queen's Attack II 中的函数返回错误答案
- access-control - Azure Key Vault 中的密钥权限
- python - 使用 --form 将 curl 转换为 python 请求
- vue.js - 如何在 vue bootstrap 中禁用 b-modal 的 modal-ok 插槽?