https://github.com/square/okhttp

 

GitHub - square/okhttp: Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Square’s meticulous HTTP client for the JVM, Android, and GraalVM. - GitHub - square/okhttp: Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

github.com

 

http호출을 간편하게 할 수 있는 소스

 

연결 중 get방식 파라미터를 추가 해야 하는 경우 HttpUrl을 이용해서 전달하려는 파라미터를 추가 할 수 있습니다.

https://www.googleapis.com/youtube/v3/search?part=snippet&q=kpop+music&key=apikey 이런 정보를 요청하는 경우 아래의 코드 처럼 작업 해주면 됩니다.

 

 

HttpUrl httpUrl = new HttpUrl.Builder()
							 .scheme(API_SCHEME)
							 .host(API_HOST)
							 .addPathSegment("youtube")
							 .addPathSegment("v3")
							 .addPathSegment("search")
							 .addQueryParameter("part", "snippet")
							 .addQueryParameter("q", "kpop+music")
							 .addQueryParameter("key", apikey)
							 .build();
System.out.println(httpUrl.toString());
        	
Request request = new Request.Builder()
							  .url(httpUrl)
							  .get()
							  .build();

반응형
Posted by 질주하는구
,