首页 > 其他 > 详细

草稿代码,有时间整理

时间:2018-01-23 15:02:05      阅读:206      评论:0      收藏:0      [点我收藏+]
   @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;

    }

  

草稿代码,有时间整理

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!