728x90
반응형
##ARC 에서 자바 코드 확인하기
1. get 요청을 한 뒤 응답이 성공하면
2.code에서 java 코드를 복사해서 클래스 메서드에 붙여넣기
## 인텔리제이 세팅
1. 패키지
-spring web
-h2
-mysql
-jpa
-lombok
2.setting
-auto import검색 - Always, Add unambiguous imports on the fly 선택
-compiler검색 - annotation processors - enable annotaion processing 선택
##
- - 네이버 쇼핑 검색 클래스
- 실행해서 응답 확인
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package com.sparta_spring.sparta_spring_week04.utils;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
public class NaverShopSearch {
public String search() {
// ARC에서 가져온 네이버 api GET 코드
RestTemplate rest = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("X-Naver-Client-Id", "발급받은 아이디");
headers.add("X-Naver-Client-Secret", "발급받은 비밀번호");
String body = "";
HttpEntity<String> requestEntity = new HttpEntity<String>(body, headers);
// 밑의 코드에서 호출 url 변수에 검색어나 여러 변수 설정 가능
ResponseEntity<String> responseEntity = rest.exchange("https://openapi.naver.com/v1/search/shop.json?query=iphone", HttpMethod.GET, requestEntity, String.class);
HttpStatus httpStatus = responseEntity.getStatusCode();
int status = httpStatus.value();
String response = responseEntity.getBody();
System.out.println("Response status: " + status);
System.out.println(response);
return response;
}
public static void main(String[] args) {
NaverShopSearch naverShopSearch = new NaverShopSearch();
naverShopSearch.search();
}
}
|
cs |
반응형
'SpringBoot > 스파르타 웹개발의 봄 spring' 카테고리의 다른 글
[스파르타 웹개발의 봄 spring] 06 완주 후기/ 수강 할인 링크 (0) | 2021.07.25 |
---|---|
[스파르타 웹개발의 봄 spring] 03.09~10 jQuery기초 (0) | 2021.07.24 |
[스파르타 웹개발의 봄 spring] 05.07 도메인 붙이고 카카오톡에 공유해보기 (0) | 2021.07.22 |
[스파르타 웹개발의 봄 spring] 05.06 포트포워딩 & nohup 적용하기 (0) | 2021.07.22 |
[스파르타 웹개발의 봄 spring] 05.05 EC2 준비하고 배포하기 (0) | 2021.07.22 |