I'm writing a ASP.NET server in C# that needs to go get a bunch of images from an external server. The problem that I'm having is that the images are getting returned from my method, but it looks like they're only half loaded.
This is what the tile looks like when loaded thru my server (it's an OSM cycle map tile):
And this is what the tile looks like if I just open it in the browser (from the same URL, of course):
It's pretty clear to me that all of the bytes aren't making it over the wire, but I'm not sure where they're getting lost. This is what my code looks like:
private byte[] GetTile(string url)
{
var response = WebRequest.Create(url).GetResponse();
Stream respStr = response.GetResponseStream();
byte[] buf = new byte[response.ContentLength];
respStr.Read(buf, 0, buf.Length);
return buf;
}
This also doesn't feel like the right way to do this. Where are my bytes going? Is there a recommended way to wait for all of the bytes from the server to arrive before I return from the function?