0

我有这样的问题https://dev.twitter.com/discussions/4563

               if (webResponse.Headers["Content-Encoding"] == "gzip")
                {
                    byte[] bytes = UTF8Encoding.Unicode.GetBytes(stream);
                    MemoryStream ms = new MemoryStream(bytes);
                    var rstream = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(ms);
                    using (var reader = new StreamReader(rstream, Encoding.UTF8))
                    {
                        var st = reader.ReadToEnd();// Exception here: "Error baseInputStream GZIP header,  second byte doesn't match"
                        parameters = HelperMethods.GetQueryParameters(st);
                    }
                }

我使用这个库:http ://slsharpziplib.codeplex.com/

更新: 我只使用 RestClient 发布推文。对于登录,我使用:

var AccessTokenQuery = oAuthHelper.GetAccessTokenQuery(OAuthTokenKey, tokenSecret, VerifyPin);
            AccessTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(AccessTokenQuery_QueryResponse);
            AccessTokenQuery.RequestAsync(TwitterSettings.AccessTokenUri, null);
4

2 回答 2

0

看起来您收到的 gzip 响应与 SharpZipLib 所期望的不太一样。

您得到的错误来自SharpZipLib/src/GZIP/GzipInputStream.cs并且可能来自这一行:

if (magic != (GZipConstants.GZIP_MAGIC & 0xFF)) {
                throw new GZipException("Error GZIP header,  second magic byte doesn't match");
}

尝试将流保存到文件中,然后查看它。看看你是否可以用 7-zip 等解压它。然后一旦你知道出了什么问题,你就可以从那里开始。

更新:

There appears to be a solution to the problem you are having at the end of the discussion you linked to and I wanted to make sure you were aware of it:

@SMCApps I caught a break...

Dim client = New RestClient() With { _
.Authority = "https://api.twitter.com/oauth", _
.Credentials = credentials, _
.HasElevatedPermissions = True, _
.SilverlightAcceptEncodingHeader = "gzip", _
.DecompressionMethods = Silverlight.Compat.DecompressionMethods.GZip _
}
于 2012-05-04T15:06:53.983 回答
0

I faced the same problem, I solved it by updating the Hammock to latest version. You can get it at http://nuget.org/packages/Hammock

After updating, It worked only when I commented the

DecompressionMethods =Hammock.Silverlight.Compat.DecompressionMethods.GZip

line from my Oauth request. I'm not sure how n why?

于 2012-05-29T14:32:19.480 回答