验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
JSON在不同系统交互时ajax调用存在跨域问题
原始数据 复制代码
package com.open.utils;
import java.io.IOException;
import java.util.LinkedHashMap;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
public class ResponseUtil {
public static void toWrite(Object obj,HttpServletResponse response){
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expires", 0); // Proxies.
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization");
response.setHeader("Access-Control-Allow-Credentials","true");
try {
response.setContentType("text/html;charset=utf-8");
JSONObject jsonNode = new JSONObject(new LinkedHashMap());
jsonNode.put("resultInfo", obj);
response.getWriter().write(jsonNode.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}

评论列表( 1 )

大秦 2018-06-14 18:16

有很多解决方案,你可以配置代理去请求

你可以在登录后,发表评论

搜索帮助

12_float_left_people 12_float_left_close