2016-07-17 16 views
1

単純なウェブサイトからHTMLソースを取得したいだけです。Alamofire Swift get html source

@IBAction func scan_func(sender: AnyObject) { 
     Alamofire.request(.GET, "http://www.example.com") 
      .response { request, response, data, error in 
       print(request) 
       print(response) 
       print(data) 
     } 
    } 

私はすでに正常「アプリのトランスポート・セキュリティの設定」を追加し、HTTPコンテンツをロードするためのInfo.plistする「任意のロードを許可」しています。

このコードを実行すると、次のような出力しか得られません。 XCODE - hexadecimal output 私があなたを助けてくれることを願っています。

種類について

答えて

1

データの生のバイトを印刷しています。私はあなたが対応する文字列表現を印刷する方法を探していると思います。 あなたは、例えばAlamofireの提供閉鎖でこれを行うことができます:

Alamofire.request(.GET, "http://www.example.com") 
    .responseString { response in 
     print("Response String: \(response.result.value)") 
} 

(ドキュメントhereをチェックしてください)

また、あなたは文字列を自分で変換することができます:

Alamofire.request(.GET, "http://www.example.com") 
    .response { request, response, data, error in 
     print(String(data: data, encoding: String.Encoding.utf8)) 
} 

Apple String reference documentation

関連する問題