码迷,mamicode.com
首页 > 其他好文 > 详细

草稿代码,有时间整理

时间:2018-01-23 15:41:59      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:oca   mapping   类型   --   char   cal   tty   headers   print   

   @RequestMapping(value = "/hivesd", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity getHiveSampleData(@RequestBody GetHiveRequest getHiveRequest) {

        // --------------------------Post Json-------------------------------



        String hiveTableName = tableMappingService.findHiveTableNameByUserTableName(getHiveRequest);
        RestTemplate restTemplate = new RestTemplate();

        //Http 请求URL
        String url = "http://localhost:8080/test";
        //Http Header
        HttpHeaders headers = new HttpHeaders();
        // 指定请求中的媒体类型信息
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        //Accept代表发送端(客户端)希望接受的数据类型。
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        String json = "{\"k1\":\"v1\"}";
        HttpEntity<String> entity = new HttpEntity<String>(json, headers);
        String restResult = restTemplate.postForObject(url, entity, String.class);
        System.out.println(restResult);


        //-------------------------Post Form------------------------


        url = "http://localhost:8080/testnotjson";
        headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
        map.add("key", "first.last@example.com");
        map.add("key", "first.last@example.com111");
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(map, headers);
        restResult = restTemplate.postForObject(url, request, String.class);
        System.out.println(restResult);

        return null;

    }

  

草稿代码,有时间整理

标签:oca   mapping   类型   --   char   cal   tty   headers   print   

原文地址:https://www.cnblogs.com/leodaxin/p/8335713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!