zoukankan      html  css  js  c++  java
  • 跨域访问接口,传递参数

        //接收方式一( jeesite ssm)
        @RequestMapping(value = "csDemo")
        public @ResponseBody String csDemo(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
            SysChargeRegister sysChargeRegister = JSON.parseObject(request.getInputStream(),SysChargeRegister.class);
            System.out.println("sysChargeRegister.getProjectName-------------"+sysChargeRegister.getProjectName());
            System.out.println("sysChargeRegistergetProjectNumbers.-------------"+sysChargeRegister.getProjectNumbers());
            return "cds";
        }
        spring-context-shiro.xml ${adminPath}/csController/csController/csDemo = anon //shiro权限
        spring-mvc.xml <mvc:exclude-mapping path="${adminPath}/csController/csController/csDemo"/>//拦截设置
        
        //接收方式二(springboot)
        @ResponseBody
        @RequestMapping(value={"/csDemo"})
        public String csDemo(@RequestBody SysProject sysProject) throws Exception{
            String result = "";
    
            String projectName = sysProject.getProjectName();
            String projectNumbers = sysProject.getProjectNumbers();
    
            System.out.println("projectName-----" + projectName);
            System.out.println("projectNumbers-----" + projectNumbers);
            return result;
        }
        在对应的shiro设置文件中,添加对应的权限 开放csDemo接口  “anon”
        
        //发送方
        public static void main(String[] args) throws MalformedURLException {
            String url2="http://127.0.0.1:8080/csController/csController/csDemo";
            JSONObject jsonObject2=new JSONObject();
            jsonObject2.put("projectName","项目名=-=-=-==-=");
            jsonObject2.put("projectNumbers","项目编码=======-=-=-=-");
            doPost2(url2,jsonObject2);
        }
        public static String doPost2(String url, JSONObject param) {
            HttpPost httpPost = null;
            String result = null;
            try {
                HttpClient client = new DefaultHttpClient();
                httpPost = new HttpPost(url);
                if (param != null) {
                    StringEntity se = new StringEntity(param.toString(), "utf-8");
                    httpPost.setEntity(se); // post方法中,加入json数据
                    httpPost.setHeader("Content-Type", "application/json");
                }
    
                HttpResponse response = client.execute(httpPost);
                if (response != null) {
                    HttpEntity resEntity = response.getEntity();
                    if (resEntity != null) {
                        result = EntityUtils.toString(resEntity, "utf-8");
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return result;
        }
  • 相关阅读:
    C++的精度控制
    N*N矩阵的旋转 不开辟新空间
    关于内存对齐的探索
    最大公约数,最小公倍数
    冒泡排序,直接选择排序,插入排序实现
    vector function trmplate
    function template
    dijit/_WidgetBase
    DOJO之gridx
    [b0008] Windows 7 下 hadoop 2.6.4 eclipse 本地开发调试配置
  • 原文地址:https://www.cnblogs.com/ljc1212/p/15261345.html
Copyright © 2011-2022 走看看