fetch post 后台接收不到数据问题

  1. 这两天在做fetch()的post,可是传递到后台,怎么都是null,GET PUT都没有问题,就是post有问题,试过网页的没有问题,但是post的就是不行,使用了网上的

method: "POST",

            mode: "cors",

            headers: {

                "Content-Type": "application/x-www-form-urlencoded"

            }, 都不行

method: "POST",

            mode: "cors",

            headers: {

                'Content-Type': 'multipart/form-data;charset=UTF-8'

            },

            body:myData  这个也不行

后来后台改了,改成

@POST

    @Produces("application/json;charset=UTF-8")

    @Consumes(MediaType.MULTIPART_FORM_DATA)

@Path("/testzte")    

public Map testPost(@FormDataParam("username") String username,

@FormDataParam("password") String password){

System.out.println("aaa");

return null;

}

以前使用的是@FormParam,这个对于普通的是可以的,但是对于fetch是不行的

全部代码

testPost(){
        let url = 'http://192.168.1.31:8080/api/zte/mobile/testzte';
        let myData = new FormData();
        myData.append("username",'aaa');
        myData.append("password",'123456');
        fetch(url,{
            method: "POST",
            mode: "cors",
            headers: {
                'Content-Type': 'multipart/form-data;charset=UTF-8'
            },
            body:myData
        }).then((response) => response.json())
            .then((responseData) =>{
                console.log("aaa")
            }).done()
    }

@POST
    @Produces("application/json;charset=UTF-8")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Path("/testzte")    
    public Map testPost(@FormDataParam("username") String username,
            @FormDataParam("password") String password){
        System.out.println("aaa");
        return null;
    }

 

猜你喜欢

转载自blog.csdn.net/fivestar2009/article/details/83855065
今日推荐