Git Product home page Git Product logo

Comments (3)

mtak0235 avatar mtak0235 commented on August 15, 2024

service is not registered error 해결 참조
https://sundries-in-myidea.tistory.com/59
heowc/programming-study#66
https://www.nanumtip.com/qa/41688/
https://velog.io/@cco2416/%EC%A1%B8%EC%97%85%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8%EA%B3%B5%EA%B3%B5%EB%8D%B0%EC%9D%B4%ED%84%B0-%ED%8F%AC%ED%84%B8-service-key-is-not-registered-error-%ED%95%B4%EA%B2%B0-%EB%B0%A9%EB%B2%95

문자열 인코딩 디코딩 참조
https://needneo.tistory.com/65

from bulletin.

mtak0235 avatar mtak0235 commented on August 15, 2024

두번 낚였다. 사실 내 키는 "/"가 포함된 인코딩 대상자였고 UriComponentsBuilder는 기본적으로 인코딩을 안해서 .encode()를 넣어줘야 했다. 거의 장르 아침드라마
https://support.microsoft.com/ko-kr/topic/%ED%8A%B9%EC%A0%95-%ED%8A%B9%EC%88%98-%EB%AC%B8%EC%9E%90%EB%8A%94-%EC%A3%BC%EC%86%8C-%ED%91%9C%EC%8B%9C%EC%A4%84%EC%97%90-%EC%9E%85%EB%A0%A5%EB%90%9C-url%EC%97%90%EC%84%9C-%ED%97%88%EC%9A%A9%EB%90%98%EC%A7%80-internet-explorer-a8e2a966-19d6-27af-06cc-e720f25e8b02

from bulletin.

mtak0235 avatar mtak0235 commented on August 15, 2024
 public PostsSaveRequestDto getPostInOutsidePostApifake(String name) throws IOException, ParseException {

        StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/1390802/AgriFood/FdImage/getKoreanFoodFdImageList"); /*URL*/
        urlBuilder.append("?" + URLEncoder.encode("serviceKey", "UTF-8") + "=csd/9isLnOcfaTZ9sdpArdEmVSBmX2L2Ml2Upn348u0yPkPYDAqp/LkA1zWCvUKMk8/1CZIiPuDhKxvp/JmuCw="); 
/*Service Key*/
        urlBuilder.append("&" + URLEncoder.encode("service_Type", "UTF-8") + "=" + URLEncoder.encode("json", "UTF-8")); /*xml 과 json 형식 지원*/
        urlBuilder.append("&" + URLEncoder.encode("Page_No", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8")); /*페이지 번호*/
        urlBuilder.append("&" + URLEncoder.encode("Page_Size", "UTF-8") + "=" + URLEncoder.encode("2", "UTF-8")); /*한 페이지 결과 수*/
        urlBuilder.append("&" + URLEncoder.encode("food_Name", "UTF-8") + "=" + URLEncoder.encode("콩", "UTF-8")); /*음식 명 (검색어 입력값 포함 검색)*/

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<HttpHeaders> entity = new HttpEntity<>(headers);
        ResponseEntity<String> resp = restTemplate.exchange(URI.create(urlBuilder.toString()), HttpMethod.GET, entity, String.class);

        String givenData = resp.getBody();
        System.out.println("givenData = " + givenData);
        JSONParser jsonParser = new JSONParser();
        PostsSaveRequestDto givenPost = json2XService.json2PostsSaveRequestDto(givenData);
        return givenPost;
    }

    public PostsSaveRequestDto getPostInOutsidePostApifake2(String name) throws IOException, ParseException, URISyntaxException {
        StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/1390802/AgriFood/FdImage/getKoreanFoodFdImageList"); /*URL*/
        urlBuilder.append("?" + URLEncoder.encode("serviceKey", "UTF-8") + "=csd/9isLnOcfaTZ9sdpArdEmVSBmX2L2Ml2Upn348u0yPkPYDAqp/LkA1zWCvUKMk8/1CZIiPuDhKxvp/JmuCw=");
 /*Service Key*/
        urlBuilder.append("&" + URLEncoder.encode("service_Type", "UTF-8") + "=" + URLEncoder.encode("json", "UTF-8")); /*xml 과 json 형식 지원*/
        urlBuilder.append("&" + URLEncoder.encode("Page_No", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8")); /*페이지 번호*/
        urlBuilder.append("&" + URLEncoder.encode("Page_Size", "UTF-8") + "=" + URLEncoder.encode("2", "UTF-8")); /*한 페이지 결과 수*/
        urlBuilder.append("&" + URLEncoder.encode("food_Name", "UTF-8") + "=" + URLEncoder.encode("콩", "UTF-8")); /*음식 명 (검색어 입력값 포함 검색)*/

        URI uri = new URI(urlBuilder.toString());
        System.out.println("uri.toString() = " + uri.toString());
        RequestEntity request = RequestEntity
                .get(uri)
                .header("Content-type", "application/json")
                .build();
        ResponseEntity<String> givenData = restTemplate.exchange(request, String.class);
        JSONParser jsonParser = new JSONParser();
        PostsSaveRequestDto givenPost = json2XService.json2PostsSaveRequestDto(givenData.getBody());
        return givenPost;
    }
 public PostsSaveRequestDto getPostInOutsidePostApi(String name) throws IOException, ParseException, URISyntaxException {
        URI uri = UriComponentsBuilder
                .fromUriString("http://apis.data.go.kr/1390802/AgriFood/FdImage/getKoreanFoodFdImageList")
                .queryParam("serviceKey", "csd/9isLnOcfaTZ9sdpArdEmVSBmX2L2Ml2Upn348u0yPkPYDAqp/LkA1zWCvUKMk8/1CZIiPuDhKxvp/JmuCw=")
                .queryParam("service_Type", "json")
                .queryParam("Page_No", "1")
                .queryParam("Page_Size", "2")
                .queryParam("food_Name", name)
                .build()
                .encode(StandardCharsets.UTF_8)
                .toUri();
        RequestEntity request = RequestEntity
                .get(uri)
                .header("Content-type", "application/json")
                .build();
        ResponseEntity<String> givenData = restTemplate.exchange(request, String.class);
        JSONParser jsonParser = new JSONParser();
        PostsSaveRequestDto givenPost = json2XService.json2PostsSaveRequestDto(givenData.getBody());
        return givenPost;
    }

from bulletin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.