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 服务器获取不到参数问题

  • 相关阅读:
    snmp简介
    PKI简介
    小程序收藏
    mysql数据库中同一DB内倒表指令
    核心层+汇聚层+接入层
    eng
    rmon简介
    几个常用的JavaScript字符串处理函数
    C# 特性(Attribute)学习 关于 .net中[]的解释
    C#操作Excel文件(读取Excel,写入Excel)
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/14177521.html
Copyright © 2011-2022 走看看