![](https://csdnimg.cn/release/download_crawler_static/9561348/bg1.jpg)
1、 代理方法
package com.ly.view.search.acon;
import java.io.BueredOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOExcepon;
import java.net.H%pURLConnecon;
import java.net.MalformedURLExcepon;
import java.net.URL;
import javax.servlet.h%p.H%pServletRequest;
import javax.servlet.h%p.H%pServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotaon.RequestMapping;
import org.springframework.web.bind.annotaon.RequestMethod;
import sun.misc.BASE64Encoder;
/**
* html2canvas 使用跨域图片的代理类, 将图片下载到本地供 html2canvas 使用
*
* @author zhangss 2016-5-27 08:41:31
* */
@Controller
@RequestMapping(value = "proxy")
public class ProxyAcon {
@RequestMapping(value="/proxy", method = RequestMethod.GET)
public void getJwd(H%pServletRequest request,H%pServletResponse response){
String url = request.getParameter("url");
String callback = request.getParameter("callback");
if(url != "" && callback != ""){
try {
URL urlInfo = new URL(url);
if(urlInfo.getProtocol().equals("h%p") || urlInfo.getProtocol().equals("h%ps"))
{
H%pURLConnecon conn = (H%pURLConnecon)
urlInfo.openConnecon();
String contentType = conn.getContentType();
if(contentType.equals("image/png") || contentType.equals("image/jpg")
|| contentType.equals("image/jpeg") || contentType.equals("image/gif") ||
contentType.equals("text/html") || contentType.equals("applicaon/xhtml")){
if(request.getParameter("xhr2") != null){