发送帖子请求时,客户端发送的请求在语法上不正确 [英] the request sent by the client was syntactically incorrect when sending post requests

查看:139
本文介绍了发送帖子请求时,客户端发送的请求在语法上不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

myController中的方法如下

The method in myController looks like this

@RequestMapping(value="/{processId}/dependents", method=RequestMethod.POST,consumes="application/json")
@ResponseBody
public Dependents postdependent(@ModelAttribute ProcessContext process,@RequestBody Dependent dependent) {
    return process.getDependents().addDependent(dependent);
}

我的获取和删除工作完美. 但是,每当我发布帖子时,我都会收到客户端发送的请求,从语法上讲是不正确的. 发布请求的JSON:

My gets and delete work perfectly. But whenever I do a post I am getting the request sent by the client was syntactically incorrect. JSON for post request:

"{
   'dependentId' : '1003',
   'firstName'   : 'Vishu',
   'lastName'    : 'poodari',
   'birthDate'   : '1970/04/15'
}"

请尝试使用单引号将所有组合都使用,双引号将所有内容都用引号引起来.

Please I tried all combinations by using single quotes, doubles quotes everything.

我正在使用rest-shell进行操作.

I am using rest-shell for doing the operations.

请找到我的家属

public class Dependent {
    private String dependentId;
    private String firstName;
    private String lastName;
    private String birthDate;
    @JsonCreator
    public Dependent(@JsonProperty("dependentId") String dependentId, @JsonProperty("firstName") String firstName, @JsonProperty("lastName")String lastName,
            @JsonProperty("birthDate") String birthDate) {
        this.dependentId = dependentId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
    }
    public String getDependentId() {
        return dependentId;
    }
    public void setDependentId(String dependentId) {
        this.dependentId = dependentId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getBirthDate() {
        return birthDate;
    }
    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }
}

推荐答案

语法错误意味着json出现问题,请用双引号替换单引号.

syntactically incorrect means problem with the json,please replace the single quote with double.

{"dependentId" : "1003",
   "firstName"   : "Vishu",
   "lastName"    : "poodari",
   "birthDate"   : "1970/04/15"
}

还要检查json键应与您的从属类属性名称匹配,并且数据应可由解析器转换.

also check the json keys should match with your Dependent class attribute names, and the data should be convertible by the parser.

这篇关于发送帖子请求时,客户端发送的请求在语法上不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆