使用 ajax POST/GET 调用 (Angular) 请求户外身份验证令牌
Request alfresco authentication token with ajax POST/GET call (Angular)
问题来了,
我尝试使用 js (angular 4) 脚本从我的露天社区服务器获取身份验证令牌。该请求似乎被 "CORS header missing"...
阻止
login/password 没问题,因为我可以直接在浏览器中尝试登录 URL,我得到了预期的结果 (xml),如下所示:
https://www.my-url.com/alfresco/service/api/login?u=username&pw=password
我得到这个结果:
现在,我来到我的网络应用程序,我需要从 http 调用中检索这张票,就像这样(使用 angular 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 变量进行了硬编码,我还尝试将它们命名为 "user" & "password",我也尝试了 GET 方法,但没有任何变化,我唯一得到的东西是Cors问题。控制台结果:
OPTIONS XHR https://www.my-url.com/alfresco/service/api/login
[HTTP/1.1 200 OK 39 ms]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource ... Reason: CORS header
'Access-Control-Allow-Origin' missing.
请求数据:
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"
我也尝试删除我为请求手动创建的headers,但没有效果...
如何在 alfresco V5.2 中启用 CORS?放 enablecors-1.0.jar
在 modules/platform 文件夹中。
问题来了,
我尝试使用 js (angular 4) 脚本从我的露天社区服务器获取身份验证令牌。该请求似乎被 "CORS header missing"...
阻止login/password 没问题,因为我可以直接在浏览器中尝试登录 URL,我得到了预期的结果 (xml),如下所示:
https://www.my-url.com/alfresco/service/api/login?u=username&pw=password
我得到这个结果:
现在,我来到我的网络应用程序,我需要从 http 调用中检索这张票,就像这样(使用 angular 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 变量进行了硬编码,我还尝试将它们命名为 "user" & "password",我也尝试了 GET 方法,但没有任何变化,我唯一得到的东西是Cors问题。控制台结果:
OPTIONS XHR https://www.my-url.com/alfresco/service/api/login [HTTP/1.1 200 OK 39 ms]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource ... Reason: CORS header 'Access-Control-Allow-Origin' missing.
请求数据:
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"
我也尝试删除我为请求手动创建的headers,但没有效果...
如何在 alfresco V5.2 中启用 CORS?放 enablecors-1.0.jar 在 modules/platform 文件夹中。