-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
允许浏览器跨域请求AndServer #305
Comments
在 public class AllowOrigin {
public static void allow(HttpResponse response, HttpMethod... methods) {
String methodHeader = TextUtils.join(",", methods);
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", methodHeader);
response.setHeader("Access-Control-Allow-Headers", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Allow", methodHeader);
}
}
...
@RequestMapping(method = {RequestMethod.PUT, RequestMethod.OPTIONS}, path = "/user/delete")
public String manageCaseInject(HttpRequest request, HttpResponse response) {
HttpMethod method = request.getMethod();
if (method == HttpMethod.OPTIONS) {
AllowOrigin.allow(response, HttpMethod.PUT, HttpMethod.OPTIONS);
return "Allow Any Origin.";
}
...
} |
2.1.6版本已经支持了 |
@crossorigin注解来支持跨域 没有效果? |
请问一下,是否支持外网访问,现在是需要客户端和服务端是在同一个局域网,或者相同形式连接同一个网络,比如WiFi,那么客户可以访问到服务端; |
@SmallRedSister 支持,你的问题不在于软件框架,而在于网络搭建。所有的网络都是局域网,公司/家里的路由器下是小局域网,所以路由器下的设备能互相访问,如果想支持跨公司/家访问,就是在国家/世界这个大局域网下了,也就是你说的外网,这个外网的路由器是电信运营商(更准确说是根服务器,为方便理解,简化到运营商),所以你需要去运营商那里搞定一个固定ip,这个固定ip的分配给你的设备,然后网线头直接连接你手机,你手机就能被外网通过ip访问了(需要域名的话,买个域名解析到该ip即可)。(当然,现实中中网线头肯定是连接路由器/锚的,然后通过路由器设置重定向到局域网的某个子ip上)。 |
@yanzhenjie 感谢您的回复,我悟了,开始觉得好玩起来了~ |
外部服务器的网页访问Android website提供的本地资源怎样解决跨域问题啊 |
No description provided.
The text was updated successfully, but these errors were encountered: