2017-10-11 125 views
0

這是問題所在,露天認證令牌/ GET調用(角)

我嘗試從一個js我的露天社區服務器(角4)腳本獲得認證令牌。請求似乎被「CORS頭失蹤」被封鎖...

登錄/密碼都OK,因爲我可以在瀏覽器中直接嘗試登錄URL,我得到預期的結果(XML)是這樣的:

https://www.my-url.com/alfresco/service/api/login?u=username&pw=password

我得到這個結果:

enter image description here

現在,我來給我的web應用程序,我需要從一個HTTP調用檢索此票,像這樣(與角4服務):

getTicket(user: User): Observable<boolean>{ 
    let headers = new Headers(); 
    headers.append('Access-Control-Allow-Origin','*'); 
    return this.http.post('https://www.my-url.com/alfresco/service/api/login',{'u':'username','pw':'password'},{headers:headers}).map(response => { 
     console.log('response : '+JSON.stringify(response)); 
    }); 
} 

我硬編碼了U/PW變量,我也嘗試命名爲「用戶」 &「密碼」,我試圖GET方法了,但是沒有什麼變化,我回來的僅僅是包含CORS問題。結果在控制檯:

選項XHR https://www.my-url.com/alfresco/service/api/login [HTTP/1.1 200 OK 39毫秒]

跨來源請求阻止:同源策略不允許讀 遠程資源...原因:CORS頭 'Access-Control-Allow-Origin'缺失。

請求數據:

Response Headers : 
Allow: "OPTIONS, GET, POST" 
Content-Length: "0" 
Date : "Wed, 11 Oct 2017 14:37:45 GMT" 
Server: "Apache-Coyote/1.1" 

Request Headers : 
Host : "www.my-url.com" 
User-Agent : "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" 
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" 
Accept-Language : "en-US,en;q=0.5" 
Accept-Encoding: "gzip, deflate" 
Access-Control-Request-Method: "POST" 
Access-Control-Request-Headers: "access-control-allow-origin" 
Origin: "http://localhost" 
Connection: "keep-alive" 

我也試着刪除我手動創建請求頭,但沒有效果...

+3

你在室外無法使用CORS嗎? –

+0

嗨@Sanjay Patel感謝您的評論。嗯,我想它的啓用,因爲我的http在瀏覽器中工作。順便說一句,我做了幾個搜索如何啓用cors在露天,但沒有發現任何明確/相關的...你能幫我解決這個問題嗎? – Julo0sS

+0

你正在使用哪個版本的露天場景? –

回答

1

如何啓用露天V5.2 CORS?在模塊/平臺文件夾中放置enablecors-1.0.jar

+0

我的Alfresco版本是5.1.0(r127059-b7)這不起作用。我仍然有這個「錯過標題在迴應」錯誤...奇怪... – Julo0sS

+0

感謝您的幫助,你沒有指向我正確的方向,我發現這一點:https://community.alfresco.com/message/812776 -authentication-json-parse-error-with-reactjs-using-alfresco-51e-ce-login-rest-api?q = Alfresco%205.1%20CORS#comment-813702它解決了我的問題:) – Julo0sS