0

I'm trying to download a JSON file from a ParseHub API I created for a local website. If I type the URL into the browser, I get the JSON formatted and all.

But when downloading into my C# app, it just displays random, unreadable characters like in the following image: Console app displaying the result of downloaded JSON

I tried downloading the page as a string:

Uri uri = new Uri(url); //url is the link to my API page
HttpClient wc = new HttpClient();

string json = await wc.GetStringAsync(uri);

During the debug sessions I see the unreadable characters that are downloaded and saved in the string json.

I tried the URL in "Postman", and it gives me: Postman Headers tab

Notice: it says Content-Encoding: gzip.

I think this may be the issue.

Any help is appreciated.

Thanks, Andrew

Drew
  • 1

1 Answers1

0

If it is gzip encoded then you can get the data as a stream instead and read it via a GZipStream

Also ideally you should use WebClient instead of HttpClient. I suspect making that change alone would be sufficient for it to automatically decompress.

PhonicUK
  • 13,486
  • 4
  • 43
  • 62