居然会自动解码,要不要这么智能,弄了快一个上午,傻逼了。。。。
1、如果不能自动解析的话,就得用http://stackoverflow.com/questions/29694050/gzip-usage-in-swift
using thisNSData+GZIP.swiftlibrary to zip/unzip data from server and here is process how to use it:
- Add
NSData+GZIP.swift
file to your project. - Add
libz.dylib
library to your project. - Add a line
#include <zlib.h>
to yourProjectName-Bridging-Header.h
file. - Invoke from your Swift/ObjC files.
2、如果你和我情况一样,加一行代码就搞定了:
request.addValue("Accept-Encoding",forHTTPHeaderField:"gzip")
其他系统会自动解析,以前怎么用,现在也怎么用。
例如:
let request :NSMutableuRLRequest = NSMutableuRLRequest(URL: URL,cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy,timeoutInterval: 40) request.HTTPMethod = "GET" request.addValue("Accept-Encoding",forHTTPHeaderField: "gzip") NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue.mainQueue(),completionHandler: {(response :NSURLResponse?,data: NSData?,error: NSError?) -> Void in callback(error,data) })
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。