加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift 解析GZIP

发布时间:2020-12-14 01:35:33 所属栏目:百科 来源:网络整理
导读:居然会自动解码,要不要这么智能,弄了快一个上午,傻逼了。。。。 1、如果不能自动解析的话,就得用http://stackoverflow.com/questions/29694050/gzip-usage-in-swift using thisNSData+GZIP.swiftlibrary to zip/unzip data from server and here is proc

居然会自动解码,要不要这么智能,弄了快一个上午,傻逼了。。。。


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:

  1. AddNSData+GZIP.swiftfile to your project.
  2. Addlibz.dyliblibrary to your project.
  3. Add a line#include <zlib.h>to yourProjectName-Bridging-Header.hfile.
  4. Invoke from your Swift/ObjC files.
提问题的人设置的方法是对的,不过他的 ProjectName-Bridging-Header.h设置出错


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)
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读