JSON parsing result for friends list or batching fails on UWP app
See original GitHub issueWhenever I use the SDK for a UWP app, calling to get a friends list and/or making a batch call leads to JSON deserialization exception. This is likely due to these lines in FacebookClient.cs ~Line 614:
#if !(SILVERLIGHT || NETFX_CORE)
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.AllowWriteStreamBuffering = false;
#endif
#if NETFX_CORE
request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip,deflate";
#endif
The problem here is that this code prevents automatic decompression but tells FB that it accepts compressed results.
I was able to get around this by overriding the HttpWebRequestWrapper and setting the web request factory to return that wrapper. In the TrySetUserAgent, I then clear the accept.
public class MyHttpWebRequestWrapper : HttpWebRequestWrapper
{
public MyHttpWebRequestWrapper(HttpWebRequest request) : base(request)
{
}
public override bool TrySetUserAgent(string userAgent)
{
this.Headers[HttpRequestHeader.AcceptEncoding] = "";
return base.TrySetUserAgent(userAgent);
}
}
I could use the deserializationn handler to see that the results were not text let alone JSON. Fought with this for hours…
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Parsing Json in UWP
I'm working on UWP and I'm trying to parse this Json but can't understand why this code can't work please anyone can check...
Read more >Error when trying to use output of Parse JSON
Error when trying to use output of Parse JSON · 1. I deleted and readded the create item (several times). · 2. I...
Read more >JSON parser step
Identify structured data from a JSON payload without having to write a script. Map incoming JSON content to a complex object output that...
Read more >JSON functions | BigQuery
Inserts JSON data into a JSON array. JSON_EXTRACT, (Deprecated) Extracts a JSON value and converts it to a SQL JSON-formatted STRING or JSON...
Read more >What Is JSON and How to Handle an “Unexpected Token” ...
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me, the SDK has recently stopped working in my Windows 10 Universal Project. Requests throw the “Invalid JSON” exception as the results looked like gibberish. I think we are experiencing the same problem.
However, the SDK still works fine in my Windows 8.1 project. I encountered a similar situation recently with the Twitter SDK where web requests worked in a Windows 8.1 project but not in a Windows 10 project, and it was because Windows 10 apps enforce HTTP/2 protocol (instead of HTTP/1.1). This caused things to break, despite Microsoft’s promise that nothing needs to be changed after the update.
It looks like we have to enforce protocol to HTTP/1.1, but the problem is that System.Net.HttpWebRequest in .NET Core doesn’t have a definition for ProtocolVersion.
Here is the code to create and prepare the client: