WildflyサーバーでRESTリクエストを作成しようとしています。まず、古いアプリケーションにログインしてクッキーを取得する必要があります。そのCookieは、REST要求を行う新しいアプリケーション で使用する必要があります。新しいアプリケーションは、実際の既存のものからいくつかのテンプレートです。私は、getAllEntities関数で示されるように、プロパティ、Access-Control-Allow-Credentials、token、crossDomainをプロパティの設定のようなRESTリクエストのヘッダにいくつかのオプションを試しました。AngularJSで安全でないヘッダー "cookie"とnet :: ERR_INSECURE_RESPONSEの設定を拒否しました
RESTリクエストがテストされ、以下のようにFirefoxブラウザのRestClientで正常に動作しました。
私はどのように知りません。
は、このことは、これらの2つのエラーを解決するため、私は、以前のアプリケーションから
削除トークンを取得
挿入クッキー(これが不可能であると思われます)書かれているタイトル
これはですどのようにリクエストがRestClientのように見えるん:
Method: GET
URL: https://xx.xx.xx.xx:8443/api/codes
Content-Type: application/json
Accept: application/json
Cookie: code_system_frontend=bvkkvbcp24igdgja4h5hht13p4; code=ae8be9267e8dfea86a8f54f6bd980733
これは、応答がRestClientでどのように見えるかです:
Status Code: 200 OK
Access-Control-Allow-Headers: Content-Type, Content-Disposition, Accept, responseType, X-MAC, X-TIME, Cookie
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Type, Content-Disposition, Accept
Connection: keep-alive
Content-Type: application/json
Date: Tue, 26 Jul 2016 15:22:00 GMT
Server: WildFly/9
Transfer-Encoding: chunked
access-control-allow-credentials: true
x-powered-by: Undertow/1
と、典型的なJSONレスポンスボディ:
[
{
"code": 1,
"codename": "Demo"
},
{
"code": 2,
"codename": "Gmx"
}
//AND SO ON
]
これは、コードはAngularjsであります:
function getAllEntities(entityName, addToCache) {
config = {
headers: {
'cookie':'code_system_frontend=bvkkvbcp24igdgja4h5hht13p4;code=ae8be9267e8dfea86a8f54f6bd980733',
'Content-Type': 'application/json',
'Accept': 'application/json',
'withCredentials':'true',
//'Access-Control-Allow-Credentials': 'true',
//'X-API-TOKEN': undefined,
//'token':undefined,
//crossDomain: true
},
data: ''
};
return $http.get(endPoints.api + entityName, config)
.then(getAllEntitiesComplete)
.catch(function (message) {
exception.catcher('XHR Failed for getAllEntities for entity ' + entityName)(message);
return $q.reject(message);
logger.info('Message ' + message);
});
function getAllEntitiesComplete(data, status, headers, config) {
var entities = data.data;
if (addToCache) {
service.cachedLookups[entityName] = entities;
service[entityName + 's'] = entities;
}
return entities;
}
}
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Content-Type: application/json
Host: XX.XX.XX.XX:8443
Origin http://admin.dev.xxxxxxxx.xxx
Referer http://admin.dev.xxxxxxxx.xxx/xx/codes
User-Agent Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
token fake token for anonymous user
withCredentials true
そして私はまた、Firebugのに警告を得る:Firebugので
リクエスト・ヘッダーを:Firebugので0私が手
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
remote resource at https://xx.xx.xx.xx:8443/xxxxxxxx/api/code. (Reason:
CORS header 'Access-Control-Allow-Origin' does not match '*').
そして私はので、私のコードでこのエラーが出る:
Error: XHR Failed for getAllEntities for entity suborder Object { status=0, config={...}, data=null, more...}
クロームでは、
Refused to set unsafe header "cookie"
と
net::ERR_INSECURE_RESPONSE