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

  • 相关阅读:
    软件测试描述错误
    软件测试homework2
    第九次
    第七次作业
    第六次作业
    第五次作业
    第四次作业
    第三次
    软件测试Lab2 Selenium及自动化测试
    软件测试(四)主路径覆盖hw3
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/14177521.html
Copyright © 2011-2022 走看看