투케이2K

180. (ios/swift) [간단 소스] 웹뷰 (wkwebview) 로드 시 post 방식 사용해 호출 실시 본문

IOS

180. (ios/swift) [간단 소스] 웹뷰 (wkwebview) 로드 시 post 방식 사용해 호출 실시

투케이2K 2022. 9. 1. 14:52
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT

 

[소스 코드]

        // -----------------------------------------
        // [실제 웹뷰 주소 로드]
        
        // [초기 웹뷰 로드 주소 설정 실시]
        var _url = "http://jsonplaceholder.typicode.com/posts?"
        
        
        // [post 쿼리 스트링 데이터 설정 실시]
        _url = _url + "id=" + "1".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
        _url = _url + "&" + "userId=" + "1".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
        
        
        // [URL 지정 실시]
        let url = URL (string: _url) // 웹뷰 로드 주소
        
        
        // [URLRequest 지정 실시]
        var request = URLRequest(url: url! as URL)
        request.setValue("application/x-www-form-urlencoded; utf-8", forHTTPHeaderField: "Content-Type")
        request.httpMethod = "POST"
        
        
        // [웹뷰 로드 수행 실시]
        self.main_webview!.load(request)
        
        // -----------------------------------------
 

[결과 출력]

 

 

반응형
Comments