无法通过AJAX将POST json请求发送到REST Web服务

时间:2013-08-31 10:48:56

标签: java jquery ajax rest

问题:我正在尝试向远程服务器上的Rest Web Service发送ajax post请求,该请求会产生JSON响应。

在使用Advanced Rest Client进行测试时,以及针对类似网址和发布数据的cURL进行测试时,我收到了所需的响应,但是如果我尝试通过jquery发送相同的请求,请求会HTTP 400 Status Code (The request sent by client was syntactically incorrect)它适用于GET和POST。

这是jquery函数:

$.support.cors = true; 
    $.ajax({     
    type: "POST",
    url: 'http://localhost:8089/myschool/rest/report/firstrequest/json',
     data:'{"studentList":[{"name":"Abhi","marks":"23"}], "classGID":"9de6f363-cb53-4845-ab7e-1e7c8bc7b33b","subjectGID":"1fd61614-5027-4daf-ac52-33c18cc86afd","School":"LKSEC"}',  
   dataType:"json",
   contentType: "application/json; charset=utf-8",
   cache:"false",
   async:"true",
   processdata:"false",
   success: function(html)
    {
        ss=html; 
        console.log(ss);
    },
   error:function(error)
   {
    console.log(error.status)
   },
   complete:function(html){
   console.log()
   }
        });

这是cURL:

    curl -X POST -H "Content-Type: application/json" 
-d '{"studentList":[{"name":"Abhi","marks":"23"}], "classGID":"9de6f363-cb53-4845-ab7e-1e7c8bc7b33b","subjectGID":"1fd61614-5027-4daf-ac52-33c18cc86afd","School":"LKSEC"}' 
http://localhost:8089/myschool/rest/report/firstrequest/json

0 个答案:

没有答案