以下のルーチンのようなものは、特定の URL (例: http://covers.oreilly.com/images/0636920022886/bkt.gif ) に対していくつかの異なる環境で機能しますが、Azure では次の例外で失敗します。
System.ArgumentException: パラメーターが無効です。System.Drawing.Image.FromStream (ストリーム ストリーム、ブール値の useEmbeddedColorManagement、ブール値の validateImageData) で System.Drawing.Image.FromStream (ストリーム ストリーム) で
いずれの場合も、問題のアセンブリは System.Drawing、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b03f5f7f11d50a3a であるため、受信したデータが Azure で何らかの形で異なると想定しています。
public static DimensionResult Is404(string url)
{
DimensionResult result = null;
HttpWebRequest request = Http.PrepareGetRequest(new Uri(url), false, false, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
request.Timeout = 2500;
request.Method = "GET";
request.AddRange(0, 2048);
request.KeepAlive = false;
request.AllowAutoRedirect = true;
try
{
result = new DimensionResult();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
result.ContentEncoding = response.ContentEncoding;
result.Url = response.ResponseUri.ToString();
result.Is404 = (response.StatusCode != HttpStatusCode.PartialContent && response.StatusCode != HttpStatusCode.OK) || System.Text.RegularExpressions.Regex.IsMatch(response.ContentType, "text|html", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (!result.Is404)
using (System.Drawing.Image image = System.Drawing.Image.FromStream(response.GetResponseStream()))
{
result.Width = image.Width;
result.Height = image.Height;
}
}
}
catch (Exception ex)
{
result.Exception = ex;
result.Is404 = true;
}
return result;
}
要求されたバイト数 (これは単純化されたバージョンです) に注目するのではなく、.NET のネットワーク スタックのどの設定が、サーバーごとの応答の違いを説明できるのでしょうか?
どちらの場合も、これまでに応答ヘッダーをログに記録しましたが、それらは同一であり、ネットワーク トレースはまだありません。
日付: 2012 年 4 月 20 日金曜日 11:47:05 GMT、サーバー: Apache、受け入れ範囲: バイト、最終更新日: 2012 年 2 月 24 日金曜日 17:21:00 GMT、コンテンツ範囲: バイト 0-2048/3556 ,Content-Length:2049,Content-Type:image/gif,Cache-Control:max-age=2592000,Expires:Sun, 20 May 2012 11:47:05 GMT,Connection:close
更新:両方の環境で受信したバイトをログに記録しましたが、それらはたまたま同一です! つまり、同じ応答ヘッダー、同じ応答長、同じ応答コンテンツ、同じアセンブリ、異なる動作です。