跨域访问代理 --解决跨域访问问题
2010-12-13 13:39
369 查看
public class ProxyServlet extends HttpServlet { @SuppressWarnings("unchecked") @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { StringBuffer query = new StringBuffer(); Enumeration e = req.getParameterNames(); while (e.hasMoreElements()) { String s = e.nextElement(); if (s != null) { query.append(s); query.append("="); query.append(req.getParameter(s)); query.append("&"); } } URL url = new URL("http://gdata.youtube.com/feeds/api/videos?" + query.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String decodedString; StringBuffer sb = new StringBuffer(); while ((decodedString = in.readLine()) != null) { sb.append(decodedString); } in.close(); resp.getOutputStream().print(sb.toString()); } catch (Exception e) { } } }
相关文章推荐
- 解决JavaScript跨域访问的问题 - JSP代理
- 利用代理页面解决html iframe跨域访问网站问题
- 利用代理页面解决html iframe跨域访问网站问题
- 利用代理页面解决html iframe跨域访问网站问题
- 用反向代理nginx proxy_pass配置解决ie8 ajax请求被拦截问题 ie8用nginx代理实现跨域请求访问 nginx405正向代理request_uri
- 完美解决SpringMVC对Ajax访问Restful接口的跨域问题(一)
- vue代理和跨域问题的解决
- 解决Js跨域访问的问题
- 解决IE浏览器中Iframe跨域访问不能读写cookie问题
- 用P3P header解决IE下iframe跨域访问时候session丢失的问题
- 使用Jsonp解决跨域数据访问问题
- 【转】js 跨域访问问题解决方法
- 用jQuery与JSONP来解决跨域访问的问题
- JavaScript(XMLHttpRequest)跨域访问解决办法及安全性问题
- 解决异步请求时跨域访问或同源策略的问题
- SpringBoot解决跨域访问的问题
- node js 解决跨域问题 ---vue axios 访问本地服务器端口报错问题
- 解决跨域访问问题
- Nginx 的使用配置并利用nginx 反向代理解决跨域问题
- openlayers3+Arcgis Server跨域问题 代理解决方式