前几天我收到了一个奇怪的错误报告,希望有人能帮助我找出罪魁祸首。我有一个插件,它使用 Facebook API 从桌面客户端程序进行调用。一位用户报告说,当他打开 Vista 的家长控制时,他遇到了运行时异常。
详细的错误报告可在此处获得,并且我已经验证 Vista 的家长控制确实是问题所在。即使没有站点被阻止,即使http://api.facebook.com
是特别允许的,我仍然得到异常。
犯法方法如下。具体来说,该行string result = reader.ReadToEnd();
是引发异常的地方。
private static XmlDocument ExecuteQuery(SortedDictionary<string, string> parameters,
string secretKey)
{
string query = GetQueryFromParameters(parameters, secretKey);
HttpWebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FACEBOOK_REST_URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// Write the POST parameters to Facebook.
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(query);
writer.Close();
// Get a response.
response = request.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
// Getting the response must have thrown an HTTP error. We can still try to get the
// response from the caught exception though.
response = we.Response as HttpWebResponse;
}
if (response != null)
{
// Read the response.
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();
reader.Close();
response.Close();
XmlDocument responseXml = new XmlDocument();
responseXml.LoadXml(result);
return responseXml;
}
else
{
throw new FacebookException(Resources.FacebookResponseError);
}
}
显然,我应该捕获 IOException,而不是让它成为运行时异常。但即便如此,问题仍然存在。我花了一些时间在谷歌上搜索这个问题,但没有找到关于家长控制的任何内容。
有什么建议么?谢谢!