我试图添加一些标头以允许 CORS,它以前工作得很好,但这次它给了我一个 Restlet1001 连接器错误,代码相同
Form responseHeaders = addHeader((Form) getResponse().getAttributes().get("org.restlet.http.headers"));
if (responseHeaders != null){
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
所以这是调用add header方法的代码,add header方法是:
public static Form addHeader(Form responseHeaders){
if (responseHeaders == null) {
responseHeaders = new Form();
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Allow-Headers", "authCode");
responseHeaders.add("Access-Control-Allow-Headers", "origin, x-requested-with, content-type");
return responseHeaders;
}
return null;
}
经过相当多的尝试和错误和谷歌,我仍然不知道为什么它给了我:
2013-07-07 19:39:24 127.0.0.1 - - 8015 GET /api/v1.0/users/findSession - 200 - 0 159 http://localhost:8015 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 -
2013-07-07 19:39:24 127.0.0.1 - - 8015 GET /api/v1.0/users/findSession - 1001 - 0 1 http://localhost:8015 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 -
2013-07-07 19:39:24 127.0.0.1 - - 8015 GET /api/v1.0/users/findSession - 1001 - 0 1 http://localhost:8015 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 -