[英]How to unpack gzip QueryResponse in twitter api wp7?
I have problem like this https://dev.twitter.com/discussions/4563 我有这样的问题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);
}
}
I use this lib: http://slsharpziplib.codeplex.com/ 我使用这个库: http : //slsharpziplib.codeplex.com/
Update: I use RestClient for post tweet only. 更新:我仅将RestClient用于发布推文。 For login I use:
对于登录,我使用:
var AccessTokenQuery = oAuthHelper.GetAccessTokenQuery(OAuthTokenKey, tokenSecret, VerifyPin);
AccessTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(AccessTokenQuery_QueryResponse);
AccessTokenQuery.RequestAsync(TwitterSettings.AccessTokenUri, null);
It looks like the gzip response you are receiving isn't quite what SharpZipLib is expecting. 您收到的gzip响应似乎与SharpZipLib所期望的不一样。
The error you are getting is from SharpZipLib/src/GZIP/GzipInputStream.cs and is probably from this line: 您收到的错误是来自SharpZipLib / src / GZIP / GzipInputStream.cs ,并且可能是从以下行:
if (magic != (GZipConstants.GZIP_MAGIC & 0xFF)) {
throw new GZipException("Error GZIP header, second magic byte doesn't match");
}
Try saving the stream to a file and then take a look at it. 尝试将流保存到文件中,然后对其进行查看。 See if you can unpack it with 7-zip, etc. Then once you know what's wrong you can go from there.
看看是否可以使用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...
@SMCApps我休息了...
Dim client = New RestClient() With { _ .Authority = "https://api.twitter.com/oauth", _ .Credentials = credentials, _ .HasElevatedPermissions = True, _ .SilverlightAcceptEncodingHeader = "gzip", _ .DecompressionMethods = Silverlight.Compat.DecompressionMethods.GZip _ }
I faced the same problem, I solved it by updating the Hammock to latest version. 我遇到了同样的问题,我通过将Hammock更新到最新版本解决了该问题。 You can get it at http://nuget.org/packages/Hammock
您可以在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. 我的Oauth请求中的一行。 I'm not sure how n why?
我不确定为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.