代理不更改为GET方法

时间:2016-10-18 15:31:01

标签: rally

在app中,我需要更改代理以使用GET方法来读取数据而不是OPTIONS方法。我试图为代理设置'方法'但它似乎没有生效。

var operation = new Ext.data.Operation({
  action: 'read',
});

var proxy = new Ext.data.proxy.Ajax({
  type: 'ajax',
  url: testURL,
  method: 'GET',
  withCredentials: true
});                

proxy.read( operation );

从调试器请求标头(通知OPTIONS)

OPTIONS /web/datasource?_dc=1476803593106&page=1&start=0&limit=25 HTTP/1.1
Host: <removed>
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: https://rally1.rallydev.com
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36
Access-Control-Request-Headers: x-requested-with
Accept: */*
Referer: <hidden>
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8

以下代码有效但不独立于数据存储:

var createCORSRequest = function(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
    // Most browsers.
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    // IE8 & IE9
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
};

var url = testURL;
var method = 'GET';
var xhr = createCORSRequest(method, url);

xhr.onload = function() {
  // Success code goes here.
  alert( xhr.response );
};

xhr.onerror = function() {
  // Error code goes here.
};

xhr.withCredentials = true;
xhr.send();

0 个答案:

没有答案