dongyan8896 2018-11-15 09:49
浏览 86

如何在GoLang中处理内容类型azip和内容编码application / a-gzip?

I am trying to use App Store Connect API to download finance and sales reports using GoLang.

I successfully connected a call to App Store API server and receiving the correct output.

By i am not able to download that reports as they are sending the response in bytes with the content type "azip".

Below is my Go Code:

url := "https://api.appstoreconnect.apple.com/v1/salesReports?filter[frequency]=DAILY&filter[reportType]=SUBSCRIPTION_EVENT&filter[reportSubType]=SUMMARY&filter[vendorNumber]=87389901&filter[reportDate]=2018-10-12&filter[version]=1_1"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Authorization", "Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IjZROUM1WVc0N1QifQ.eyJpc3MiOiI2OWE2ZGU5MC00NGNiLTQ3ZTMtZTA1My01YjhjN2MxMWE0ZDEiLCJleHAiOjE1NDIyNzM0MzcsImF1ZCI6ImFwcHN0b3JlY29ubmVjdC12MSJ9.fC4zmgaUZZTwtopt9gaSl6HUtACNjBvWi5VNa366d5FI5l_00wM1U2cBi26a0jtB8yuZOufDSQA0MB5iMC332g")

res, _ := http.DefaultClient.Do(req)

fmt.Println(res.Header.Get("Content-Encoding"))

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))

Below are the headers what i am getting.

Server = daiquiri/3.0.0
Date  = Thu, 15 Nov 2018 12:01:47 GMT
Content-Type = application/a-gzip
Transfer-Encoding = chunked
Connection  = keep-alive
requestId = 24e0c473-a35f-4374-846c-d17007c49978
Content-Encoding = agzip
Content-Disposition → attachment;filename = Subscription_Event_87389901_20181012_V1_1.txt.gz
x-reports-filename = Subscription_Event_87389901_20181012_V1_1.txt.gz
x-reports-download-version = 1_1
Strict-Transport-Security = max-age=31536000; includeSubDomains
X-XSS-Protection = 1; mode=block
X-Content-Type-Options = nosniff
Host = reportingitc-reporter-internal.corp.apple.com
X-Frame-Options = SAMEORIGIN
X-Request-ID = QSBM3FPCNVUODU2H5FCQRL5T
X-Rate-Limit = user-hour-lim:3600;user-hour-rem:3599;
x-daiquiri-instance = daiquiri:38493001:pv50p00it-hyhk12043901:13987:18O38

It may be possible i am doing something wrong. But please let me know how can i store this as a file using GoLang.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 matlab有关常微分方程的问题求解决
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考