4

I have a json file named test.json in the root of my website. which is hosted on a Windows Server 2012 R2 in IIS version 6.2. the json file is 2698KB. I have written a small C# console application which is very simple it accesses the file and then writes the byte array to a file.

class Program
{
    static void Main(string[] args)
    {
        WebClient client = new WebClient();
        byte[] data = client.DownloadData("http://mywebsite/test.json");
        File.WriteAllBytes("D:\\test\\download.json", data);
    }
}

When I run this exe on my local machine, and then compare the downloaded file with the original file in the website root, the two are identical. But when I run the exe on the server (the same server which is hosting the site) and compare the downloaded file with the original the downloaded file is always corrupted, and each time in a different place or a different way. For example:

Original Json:

"Deleted" : false,
"CreateDate" : "2012-09-04T07:57:41.5947956",
"ModUser" : "CFR",

Corrupt Json:

"Language" : null,
"Dell," Lookup ":null," LanguageId ":1,"

It is just corrupt and makes no sense and cannot be parsed. This functionality was working fine on this website for a long time, and now the files are always corrupt. If I download the json through Internet Explorer it is also corrupt when using the browser on the server. But not from my local machine. I don't know what could be causing this problem. Any help or tips would be really appreciated.

Tim Pickin
  • 369
  • 4
  • 15
  • Are you sure the server is actually talking to the same site? Does it have a possibly-broken proxy between it and the website? (It's not clear whether by "the server" you mean "the same machine serving the website I'm downloading from".) – Jon Skeet Jan 29 '16 at 07:27
  • I am connecting to the server using a remote desktop connection. I ping the site from the server and from my local machine, and both times I get a reply from the same ip address. I am not sure how I would check for a proxy. And sorry, yes you are correct the server is the same machine which is hosting the website which I am downloading from. – Tim Pickin Jan 29 '16 at 07:30
  • If you open the file in the browser on your windows server, is it then corrupt? – Christian Gollhardt Jan 29 '16 at 07:42
  • That is a good question but unfortunately the browser on the windows server is IE11 and cannot open the file in the browser, it only says, "Do you want to open or save test.json" – Tim Pickin Jan 29 '16 at 07:48
  • Yes, open it with editor :) – Christian Gollhardt Jan 29 '16 at 07:50
  • Hi Christian, when I open it in the editor, it is not corrupted. Then it works!! – Tim Pickin Jan 29 '16 at 07:57
  • Try `iisreset` with CMD as Administrator... Not sure if this will help... – Christian Gollhardt Jan 29 '16 at 08:20

1 Answers1

2

I have found a workaround. I added mywebsite to the hosts file on the webserver with the localhost ip 127.0.0.1 and now when I access the json data it is no longer corrupt.

Tim Pickin
  • 369
  • 4
  • 15