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;
        }
  • 相关阅读:
    Python for i 循环
    Python 输入分数并评
    用户名和密码的输入
    cocos2d-x 3.0学习
    VS2008 ShotKey
    Cocos2d-x 3.0的安装方法
    VFC
    一、在WIN7 64位系统平台,VS2013环境下安装WTL90_4090_RC1(2014-04-01)
    http://www.vcf-online.org/
    Win7 64位 VS2012 安装 Qt5
  • 原文地址:https://www.cnblogs.com/ljc1212/p/15261345.html
Copyright © 2011-2022 走看看