gzip压缩API呼叫swift
我正在使用Swift工作的API工作,该API需要您在HTTP请求的主体中使用GZIP或Deflate发送JSON。如何将下面的testEventModel转换为所需的压缩JSON格式?
struct EventModel: Codable {
var eventType: String
var eventName: String?
}
var testEventModel = EventModel(eventType: "TestEvent", eventName: "TestName")
I'm working in Swift with an API that requires you to send JSON compressed using gzip or deflate in the body of your HTTP request. How would I convert testEventModel below into the required compressed JSON format?
struct EventModel: Codable {
var eventType: String
var eventName: String?
}
var testEventModel = EventModel(eventType: "TestEvent", eventName: "TestName")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是将现有库用于gzzipping内容,例如: https://github.com/ 1024JP/gzipswift 。然后,您的代码看起来如下:
Simplest way, would be to use an existing library for gzipping content, like this one: https://github.com/1024jp/GzipSwift . then your code could look like follows: