「Ios/swift/外部ライブラリ/Alamofire」の版間の差分
提供: 初心者エンジニアの簡易メモ
行14: | 行14: | ||
==使い方== | ==使い方== | ||
import Alamofire | import Alamofire | ||
+ | Alamofire.request(.GET, "https://twitter.com") | ||
+ | .responseJSON { response in | ||
+ | print(response.request) | ||
+ | print(response.response) | ||
+ | } | ||
+ | |||
+ | 出力 | ||
+ | Optional(<NSMutableURLRequest: 0x15de5ce90> { URL: https://twitter.com }) | ||
+ | Optional(<NSHTTPURLResponse: 0x15de03170> { URL: https://twitter.com/ } { status code: 200, headers { | ||
+ | "Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0"; | ||
+ | "Content-Encoding" = gzip; | ||
+ | "Content-Length" = 32873; | ||
+ | "Content-Type" = "text/html;charset=utf-8"; | ||
+ | Date = "Thu, 23 Jun 2016 03:08:19 GMT"; | ||
+ | Expires = "Tue, 31 Mar 1981 05:00:00 GMT"; | ||
+ | "Last-Modified" = "Thu, 23 Jun 2016 03:08:19 GMT"; | ||
+ | Pragma = "no-cache"; | ||
+ | Server = "tsa_a"; | ||
+ | "Set-Cookie" = "fm=0; Expires=Thu, 23 Jun 2016 03:08:09 GMT; Path=/; Domain=.twitter.com; Secure; HTTPOnly, _twitter_sess=BAh7CSIKZmxhc2hJQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCAHToMY3NyZl9p%250AZCIlZGMzNTBjMWZiMGI5MmZlNmM1MDVmMmMyNTNjZDVjYjM6B2lkIiU0MzA2%250AN2ZiMDgzYWY4YTYyYTk5YTdiYjRmNQ%253D%253D--49410ad03124cde2eab339902b9f116860f4; Path=/; Domain=.twitter.com; Secure; HTTPOnly, guest_id=v1%3A146658349991; Domain=.twitter.com; Path=/; Expires=Sat, 23-Jun-2018 03:08:19 UTC"; | ||
+ | Status = "200 OK"; | ||
+ | "Strict-Transport-Security" = "max-age=631138519"; | ||
+ | "x-connection-hash" = a80a35cb815d23f423a94ea3bb30; | ||
+ | "x-content-type-options" = nosniff; | ||
+ | "x-frame-options" = SAMEORIGIN; | ||
+ | "x-response-time" = 157; | ||
+ | "x-transaction" = 00d8e8bec4f0; | ||
+ | "x-twitter-response-tags" = BouncerCompliant; | ||
+ | "x-ua-compatible" = "IE=edge,chrome=1"; | ||
+ | "x-xss-protection" = "1; mode=block"; | ||
+ | } }) |
2016年6月23日 (木) 12:09時点における版
Alamofireとは
httpに非同期でアクセスできるライブラリ
インストール
$ vi Podfile platform :ios, '9.0' target 'Helloworld' do use_frameworks! pod 'Alamofire', '~> 3.0' end
$ pod install
使い方
import Alamofire Alamofire.request(.GET, "https://twitter.com") .responseJSON { response in print(response.request) print(response.response) }
出力
Optional(<NSMutableURLRequest: 0x15de5ce90> { URL: https://twitter.com }) Optional(<NSHTTPURLResponse: 0x15de03170> { URL: https://twitter.com/ } { status code: 200, headers { "Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0"; "Content-Encoding" = gzip; "Content-Length" = 32873; "Content-Type" = "text/html;charset=utf-8"; Date = "Thu, 23 Jun 2016 03:08:19 GMT"; Expires = "Tue, 31 Mar 1981 05:00:00 GMT"; "Last-Modified" = "Thu, 23 Jun 2016 03:08:19 GMT"; Pragma = "no-cache"; Server = "tsa_a"; "Set-Cookie" = "fm=0; Expires=Thu, 23 Jun 2016 03:08:09 GMT; Path=/; Domain=.twitter.com; Secure; HTTPOnly, _twitter_sess=BAh7CSIKZmxhc2hJQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCAHToMY3NyZl9p%250AZCIlZGMzNTBjMWZiMGI5MmZlNmM1MDVmMmMyNTNjZDVjYjM6B2lkIiU0MzA2%250AN2ZiMDgzYWY4YTYyYTk5YTdiYjRmNQ%253D%253D--49410ad03124cde2eab339902b9f116860f4; Path=/; Domain=.twitter.com; Secure; HTTPOnly, guest_id=v1%3A146658349991; Domain=.twitter.com; Path=/; Expires=Sat, 23-Jun-2018 03:08:19 UTC"; Status = "200 OK"; "Strict-Transport-Security" = "max-age=631138519"; "x-connection-hash" = a80a35cb815d23f423a94ea3bb30; "x-content-type-options" = nosniff; "x-frame-options" = SAMEORIGIN; "x-response-time" = 157; "x-transaction" = 00d8e8bec4f0; "x-twitter-response-tags" = BouncerCompliant; "x-ua-compatible" = "IE=edge,chrome=1"; "x-xss-protection" = "1; mode=block"; } })