Angular restAPI调用java返回400错误

时间:2016-01-08 05:31:24

标签: java angularjs hibernate

我试图通过angularjs调用hibernate restapi,但它返回400错误,但是当我通过post man进行调用时它返回值, 我的代码为follwos

java代码

@RequestMapping(value = "/sample.html", method = RequestMethod.POST)
@ResponseBody
public static Response getCustomerDetails(@RequestParam("userId")Long userId, 
                                              @RequestParam("itemId")ArrayList<Long> itemId)  throws AViewException
{
    customerDetails=new object({"customerName":xxx});
    return Response.status(Status.OK).entity(customerDetails).build();
}

angularjs

var itemId=[374,375,376,377];
$scope.selected ={
            userId:$rootScope.user.userId,
            itemId:itemId
        };
console.log($scope.selected);       
$http({ method: 'POST',
    url: 'http://10.3.2.204:8080/aview/sample.html',                        
    headers: {
            'Authorization': 'Basic dGVzdDp0ZXN0',
            'Content-Type': undefined,
            'Accept': '*/*'},                       
    data: JSON.stringify($scope.selected)

})
.success(function(data, status, headers, config) 
{   
    console.log(data);
     $scope.data = data;
     console.log($scope.data);

})
.error(function(data, status, headers, config) 
{
    alert("error"); 
    console.log(data);                                  
});

错误

HTTP Status 400 -

type Status report

message

description The request sent by the client was syntactically incorrect.
Apache Tomcat/7.0.41

0 个答案:

没有答案