1

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

在使用 Advanced Rest Client 以及类似 url 和 post 数据的 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 -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
4

0 回答 0