使用Post的webservice呼叫

时间:2014-12-12 14:35:33

标签: java ajax web-services class post

我是webservice和ajax的新手..我试图使用POST方法调用web服务。 我尝试使用Postman(谷歌浏览器应用程序)调用它,我得到了响应,但当我尝试使用Ajax时,我收到错误 以下是我做的事情:

我的代码:(我写了一篇JS,其中包含了以下代码并尝试了所有注释选项):

$.ajax({
    crossDomain: true,
    url : 'https://yxyxyxyxyx/search/v1/query.json', 
    type : 'POST',
    dataType : "json",
    data: {appId: "a9b475a079",query: "dhcp"},
    //async : true,
    //headers: {"Content-type": "application/json"},
    headers: { 'Access-Control-Allow-Origin': '*' },
    //contentType: "application/json; charset=utf-8",
    //headers: ('Access-Control-Allow-Methods: GET, POST, OPTIONS'),
    //headers: ('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'),
    //headers: ('Access-Control-Allow-Credentials: true'),
    // Access-Control-Allow-Origin: "http://localhost:8080",
    // headers: { 'Access-Control-Allow-Origin': '*' },
    //userAgent : 'Mozilla/22.0',

    success: function(data){

     alert("hi success");
    },
    error: function(data) {alert("An error occured: " + data.status + " " + data.statusText);
    });

我在错误中收到警报并在调试时收到以下错误:

XMLHttpRequest cannot load https://www.sample.search/v1/query.json. The request was redirected to 'https://www.sample/obrareq.cgi?wh%3DCCI-STG4%20wu%3D%2Fuesps%…n-tools-stage.cisco.com%20ru%3D%252Fuesps%252Fsearch%252Fv1%252Fquery.json', which is disallowed for cross-origin requests that require preflight.

我尝试了所有选项来解决我在网上找到的CROS选项......我们还有其他方法可以解决它。

如果我们可以使用也可以达到目的的java类来帮助我

0 个答案:

没有答案