标签:
js提交请求给别的应用实例或者别的服务器,由于同源策略,存在js跨域的情况,我所知道两种处理方式;
1、jquery ajax+jsonp
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$.ajax({
url:"",
dataType:‘jsonp‘,
data:‘‘,
success:function(result) {
},
timeout:3000
});
</script>
这样便可以利用jsonp解决跨域问题;
2、在后台作http转发实现跨域问题
请求到同源工程的代理action,在该代理上做一次http转发,请求目的服务器的action,如下:
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod("远程action地址");
RequestEntity requestEntity = new InputStreamRequestEntity(req.getInputStream(),req.getContentLength(),req.getContentType());
postMethod.setRequestEntity(requestEntity);
client.getHttpConnectionManager().getParams().setConnectionTimeout(120000);//设置超时
client.executeMethod(postMethod);//执行请求
String bodystr = postMethod.getResponseBodyAsString();//返回结果
标签:
原文地址:http://www.cnblogs.com/jianwei-dai/p/4807846.html