yinjihuan / monkey-api-encrypt

monkey-api-encrypt是对基于Servlet的Web框架API请求进行统一加解密操作
Apache License 2.0
793 stars 346 forks source link

umi-request请求后端不加密 #81

Open resuper opened 2 years ago

resuper commented 2 years ago

postman请求响应正常,umi-request请求不正常

前端代码

import request from 'umi-request';
request.post('/api/test/encryptTransmission/',{
      // aes 加密后的字符串
      // data:Encrypt(JSON.stringify(reqData)),
      // rsa 加密后的字符串
      // data:jsEncrypt.encrypt(JSON.stringify(reqData)),
      // json对象
      data:reqData,
      headers:{
        Accept:'*/*'
      }
    }).then((res)=>{
      console.log('1');
    })

后端代码 pom.xml

<dependency>
            <groupId>com.cxytiandi</groupId>
            <artifactId>monkey-api-encrypt-core</artifactId>
            <version>1.2.RELEASE</version>
        </dependency>

springboot主启动类

@SpringBootApplication
@MapperScan(basePackages = {"com.iwhalecloud.yn.portal.mapper"})
@EnableEncrypt
public class YnPortalServerApplication {

//    @Resource
//    private MyRsaEncryptAlgorithm myRsaEncryptAlgorithm;

    public static void main(String[] args) {
        SpringApplication.run(YnPortalServerApplication.class, args);
    }

}

TestController

@RestController
@RequestMapping("/test")
public class TestController {
    @RequestMapping("/hello")
    public Result hello() {
        return Result.buildFail("-440033", "服务器正常返回,但是返回的结果告知服务器或业务不对");
    }

    @Encrypt
    @PostMapping(path = "/encryptTransmission" ,consumes="application/json")
    public Result encryptTransmission(@RequestBody MyUserDetails myUserDetails) {
        return Result.buildSuccess(myUserDetails);
    }
}

测试结果 postman image

前端项目 image

image

yinjihuan commented 2 years ago

前端项目的uri多了一个api,这个是后端项目的content-path吗?如果是的话你升级到1.2.2版本