0

我正在为 Windows Phone 编写一个 SDK 以与 Google Drive 交互,但我无法让服务器返回 gzipped 响应。正如您从我的请求中看到的那样,我已按照文档中的简短提及,但我仍然只获得原始数据:

要求:

GET https://www.googleapis.com/drive/v2/files/ HTTP/1.1
Accept: */*
User-Agent: my program (gzip)
Authorization: Bearer [removed]
Accept-Encoding: gzip
Host: www.googleapis.com
If-None-Match: "PA40KOhMf9e-1Hypww_TkG8doNA/jgiBh3LdSV9a9DAu8kcM87C_SgA"
Connection: Keep-Alive

回复:

HTTP/1.1 200 OK
Expires: Fri, 13 Sep 2013 06:31:47 GMT
Date: Fri, 13 Sep 2013 06:31:47 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
ETag: "PA40KOhMf9e-1Hypww_TkG8doNA/P9KtUv7cYy7pQSattesAaw0ejBM"
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 215811
Server: GSE
Alternate-Protocol: 443:quic

以上两个都是使用 Fiddler 捕获的。

用于创建和使用 HttpClient 的代码,我最初也包含了 deflate 方法,但是当 Google 提供的示例没有包含它时将其删除:

HttpClientHandler Handler = new HttpClientHandler();

if (Handler.SupportsAutomaticDecompression)
{
    Handler.AutomaticDecompression = DecompressionMethods.GZip;
}

HttpClient Client = new HttpClient(Handler);
Client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + Token.AccessToken);
if (Handler.SupportsAutomaticDecompression)
{
    Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "my program (gzip)" /*"DriveClient (gzip)"*/);
}

HttpResponseMessage Responce = await DriveAuthorisation.DriveHttpClient.GetAsync("https://www.googleapis.com/drive/v2/files/");

谢谢!

4

0 回答 0