我有问题。即使请求停止,代码也会输出两次错误?
当我在此代码得到一个错误时输出错误的两倍,即使我调用该函数杀死响应,注意OutputError:
private dynamic GetOauthTokens(string code)
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}",
myAppId, HttpUtility.UrlEncode(myLoginRedirectUrl), myAppSecret, code);
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string retVal = reader.ReadToEnd();
foreach (string token in retVal.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
}
catch (Exception exception)
{
OutputError("Code", exception.Message);
}
return tokens;
}
这里是我处理这件事:
protected void OutputError(string error, string message)
{
object obj = new { Status = false, Error = error, Message = message };
string objJson = JsonConvert.SerializeObject(obj);
myHttpContext.Response.Write("LinkedLook.getJson(" + objJson + ");");
myHttpContext.Response.End();
}
由于某种原因,它吐出两次......我做错了什么?
这里有多个线程吗?这种方法可以同时运行两次吗? – 2011-12-23 04:36:29