请求标签形式(post)

1、请求将参数标签化

 @PostMapping("/xxx")
    public Map<String, Object> applyXXX(@RequestBody Entity entity){
        Map<String, Object> result = new HashMap<>();
        if (StringUtils.isBlank(实体.getXm())){
            result.put("code", "003");
            result.put("message","姓名为空!请检查");
            return result;
        }
        if (StringUtils.isBlank(实体.getCard())){
            result.put("code", "003");
            result.put("message","证件号码为空!请检查");
            return result;
        }

        StringBuffer strXml = new StringBuffer();
        strXml.append("<操作*>xx操作</操作*>")
                .append("<姓名*>").append(实体.getXm()).append("</姓名*>")
                .append("<证件类型*>").append(实体.getZjlx()).append("</证件类型*>")
                .append("<证件号码*>").append(实体.getCard()).append("</证件号码*>")try {
            Call call = (Call) (new Service()).createCall();
            call.setTargetEndpointAddress(new URL(url));
            call.setOperationName(new QName("url", "接口名"));
            call.setTimeout(30000);
            String res = (String) call.invoke(new String[]{strXml.toString()});
            System.out.println(res);
            log.info("<<xxxxx>>接口调用返回结果:" + res);

            res = res.replace("<ERR>", "").replace("</ERR>", "");
            if ("00".equals(res)) {
                result.put("code", res);
                result.put("message", "调用成功");
            } else if ("01".equals(res)) {
                result.put("code", res);
                result.put("message", "已存在");
            } else {
                result.put("code", "002");
                result.put("message", "调用失败,失败原因:" + res);
            }

        } catch (ServiceException e) {
            log.error(e.getMessage());
            result.put("code","003");
            result.put("message",ERROR);
            return result;
        } catch (MalformedURLException e) {
            log.error(e.getMessage());
            result.put("code","003");
            result.put("message",ERROR);
            return result;
        } catch (RemoteException e) {
            log.error(e.getMessage());
            result.put("code","003");
            result.put("message",ERROR);
            return result;
        }
        return result;
    }
当使用POST请求时,可以通过两种方式在请求中传递多个参数:表单数据(Form Data)和 JSON 数据(JSON Data)。 1. 表单数据方式: 在HTML的表单中,使用input标签的name属性来定义参数名,value属性来定义参数值。在POST请求中,将这些参数按照key-value键值对的方式放入请求体中,以便服务器端能够正确识别参数。 示例代码: ```html <form action="example.php" method="post"> <label>Username:</label> <input type="text" name="username"><br> <label>Password:</label> <input type="password" name="password"><br> <input type="submit" value="Submit"> </form> ``` 在上面的示例中,我们通过两个input元素来定义了两个参数:username和password。当用户点击提交按钮时,这些参数会被打包成键值对的形式,放入请求体中,发送到服务器端。 2. JSON 数据方式: 在某些情况下,我们需要将多个参数打包成JSON格式的数据,通过POST请求发送给服务器。此时,我们可以使用JavaScript的JSON.stringify()方法,将多个参数转换成JSON格式的字符串,放入请求体中。 示例代码: ```javascript var data = { "username": "admin", "password": "123456" }; var xhr = new XMLHttpRequest(); xhr.open("POST", "example.php", true); xhr.setRequestHeader("Content-type", "application/json"); xhr.send(JSON.stringify(data)); ``` 在上面的示例中,我们将多个参数打包成一个JSON对象,并使用XMLHttpRequest对象发送POST请求请求体中的数据是JSON格式的字符串。注意,我们在请求头中设置了Content-type为"application/json",以表明请求体中的数据是JSON格式的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值