Android http 통신 허용

pass·2023년 8월 2일
0

Android

목록 보기
25/36

🔥 Android 에서의 http 통신에 대해 알아보자.

대부분의 경우 보안상의 이유로 https 통신을 하지만, 테스트나 예전 서비스의 경우 http 통신을 사용한다.
하지만, Android 9 부터는 기본적으로 http 통신을 허용하지 않기 때문에 http 통신을 할 수 있도록 설정을 해주어야 한다.
아래에서 모든 http 에 대한 통신을 허용하는 방법과 url 예외처리를 통해 http 에 대한 통신을 허용하는 방법을 알아보자.


✓ network_security_config.xml 파일 생성

모든 url http 허용

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

예외처리된 url http 허용

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">naver.com</domain>
        <domain includeSubdomains="true">google.com</domain>
    </domain-config>
</network-security-config>

✓ Manifest.xml 에 적용

<application
    ...
	android:networkSecurityConfig="@xml/network_security_config" >
  	...
</application>
profile
안드로이드 개발자 지망생

1개의 댓글

comment-user-thumbnail
2023년 8월 2일

좋은 글 감사합니다.

답글 달기