2017-08-11 45 views
0

我正在使用rally sdk開發自定義html儀表板,並且我想從CORS原始請求調用填充其中一個字段數據。如何從rally sdk(自定義html代碼)製作CORS原始呼叫請求?

您能否提供一些示例/鏈接如何使用rally sdk自定義html代碼進行CORS調用?

我試圖通過ajax調用它給我403例外。

var usChangeSets = story.getCollection('Changesets'); 
      console.log('usChangeSets--',usChangeSets);   
      usChangeSets.load({ 
       fetch : ['Author', 'Message', 'Uri'], 
       callback: function(records, operation, success){ 
        Ext.Array.each(records, function(changeset){           
         //Ajax api call to get details from external link 
         var blink ="https://[sonarqube]/job/Appdev/job/TestProject/api/json";      
         Ext.Ajax.request({ 
           url: blink, 
           method :'GET', 
           crossDomain: true, 
           withCredentials: true, 
           headers : { 
            'Authorization': 'Basic dsasfsfxfhfj', 
            'Content-Type': 'application/json;charset=UTF-8', 
            'Access-Control-Allow-Origin' : '*' 
           }, 
           success: function(response){ 
            var backToJs=JSON.parse(response.responseText); 
             console.log('resp data-',backToJs); 
             //console.log(backToJs['QueryResult'].Results); 

           }, 
           failure: function(response) { 
            console.log('ajax call failure'); 
           } 
          });         
         } 
      } 
} 
+0

請使用https://stackoverflow.com/posts/45628458/edit編輯/更新你的問題和粘貼在您的瀏覽器devtools控制檯中看到確切的錯誤消息。 – sideshowbarker

回答

0

您需要配置您的外部服務器以允許CORS請求。瀏覽器會自動將origin標題添加到您的請求中,然後您的服務器應使用適當的cors標題(Access-Control-Allow-Origin)進行響應。

這裏的反彈服務器如何響應來自不同來源的請求的例子:

% http https://rally1.rallydev.com/slm/webservice/v2.0/testcaseresult/54277371431 zsessionid:_5507Kn8 origin:localhost -v 
GET /slm/webservice/v2.0/testcaseresult/54277371431 HTTP/1.1 
Accept: */* 
Accept-Encoding: gzip, deflate 
Connection: keep-alive 
Host: rally1.rallydev.com 
User-Agent: HTTPie/0.9.9 
origin: localhost 
zsessionid: _55GAn8 



HTTP/1.1 200 OK 
Access-Control-Allow-Credentials: true 
Access-Control-Allow-Origin: localhost 
Access-Control-Expose-Headers: 
CF-RAY: 38cbe03c4dd45005-DEN 
Cache-Control: private,max-age=0,must-revalidate 
Connection: keep-alive 
Content-Encoding: gzip 
Content-Length: 623 
Content-Type: application/json; charset=utf-8 
Date: Fri, 11 Aug 2017 14:27:29 GMT 
ETag: "0b0e0cdae135fc6cd32fa496d7660c756" 
Expires: Thu, 01 Jan 1970 00:00:00 GMT 
P3P: CP="NON DSP COR CURa PSAa PSDa OUR NOR BUS PUR COM NAV STA" 
RallyRequestID: qs-app-103xz471u80pea8opfovz9g8gv.qs-app-1014978663 
Server: cloudflare-nginx 
Set-Cookie: __cfduid=d604a6a0fa131613b997640ead95cc5171502461649; expires=Sat, 11-Aug-18 14:27:29 GMT; path=/; domain=.rallydev.com; HttpOnly 
Set-Cookie: JSESSIONID=qs-a0;Path=/;Secure;HttpOnly 
Set-Cookie: SUBBUCKETID=209;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly 
Set-Cookie: SUBSCRIPTIONID=209;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly 
Set-Cookie: SERVERID=319fca23748f5704e88bd8741ae60476b188cf5e; path=/ 
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload; 
Vary: Accept-Encoding 
X-XSS-Protection: 1; mode=block