투케이2K

201. (ios/swift) [간단 소스] http URLSession 요청 시 헤더에 Cache-Control 캐시 컨트롤 추가 방법 본문

IOS

201. (ios/swift) [간단 소스] http URLSession 요청 시 헤더에 Cache-Control 캐시 컨트롤 추가 방법

투케이2K 2022. 9. 17. 13:07
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT

 

[소스 코드]

// [http 주소 설정 실시]
var urlComponents = URLComponents(string: fileUrl)
var requestURL = URLRequest(url: (urlComponents?.url)!)

// [http 요청 타입 지정]
requestURL.httpMethod = "GET" // GET

// [http 요청 헤더 설정]
requestURL.addValue("application/x-www-form-urlencoded; charset=utf-8;", forHTTPHeaderField: "Content-Type") // 헤더
requestURL.addValue("no-cache", forHTTPHeaderField: "Cache-Control") // 헤더

 

반응형
Comments