zoukankan      html  css  js  c++  java
  • Angular HttpClient POST 服务器(springboot)获取不到参数问题

    Angular HttpClient POST 服务器获取不到参数问题

    参数是一串json字符串,而不是一个的参数

    改前

     改后

    改前:

    //调用登录接口
        var api = 'http://127.0.0.1/authentication/form';
        var dd=this.validateForm.value;
        const httpOptions = {
          headers: new HttpHeaders({'content-type': 'application/x-www-form-urlencoded'})
          };
        this.http.post(api,{
          "username":"admin",
          "password":"123456",
          "imageCode":"2313"
        },httpOptions).subscribe((response)=>{
            console.log(response);
        });

    改后:

    transformRequest(data) {
        var str = '';
        for (var i in data) {
        str += i + '=' + data[i] + '&';
        }
        str.substring(0, str.length - 1);
        return str;
      };
    
    
    //调用登录接口
        var api = 'http://127.0.0.1/authentication/form';
        var dd=this.validateForm.value;
        const httpOptions = {
          headers: new HttpHeaders({'content-type': 'application/x-www-form-urlencoded'})
          };
        this.http.post(api,this.transformRequest({
          "username":"admin",
          "password":"123456",
          "imageCode":"2313"
        }),httpOptions).subscribe((response)=>{
            console.log(response);
        });

    Angular HttpClient POST 服务器获取不到参数问题

  • 相关阅读:
    cookie
    sql 语句
    页面宽高
    分页
    asp.net中如何防止用户重复点击提交按钮
    小试简单工厂模式之简单计算器
    用函数实现交换的疑问
    结构体变量输入输出的问题
    scanf函数输入float数需要注意的问题
    oracle学习手记(1)
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/14177521.html
Copyright © 2011-2022 走看看