我有問題。即使請求停止,代碼也會輸出兩次錯誤?
當我在此代碼得到一個錯誤時輸出錯誤的兩倍,即使我調用該函數殺死響應,注意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