-1
try
{

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.site.ru/group/" + gr);
    request.AllowAutoRedirect = false;
    request.Method = "GET";
    request.CookieContainer = cookies;
    request.UserAgent = "Opera/9.80 (Windows 7; U; en) Presto/2.9.168 Version/11.50";
    request.ContentType = "application/x-www-form-urlencoded";
    HttpWebResponse response_headers = (HttpWebResponse)request.GetResponse();
    System.IO.Stream stream = response_headers.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    string response = sr.ReadToEnd();
    sr.Close();
    /*if (response_headers.Headers["Location"].Contains("alted"))
    {
        log("[-] GROUP is " + gr + " closed\r\n");
        return -2;
    }*/
    string gash = Regex.Match(response, @"gwtHash:""(?<id>[^""]+)""").Groups["id"].Value;
    string grpId = Regex.Match(response, @"state:""st.cmd=altGroupMain&amp;st.groupId=(?<id>[^""]+)""").Groups["id"].Value;
}
catch { log("[?] Can't parse ash and grpId\r\n"); return -1; }

如果 {} 被注释,则此代码在构造时成功运行。但是当我删除评论并运行它时,我收到[?] Can't parse ash and grpId Why?=\

4

2 回答 2

3

response_headers.Headers["Location"]必须为空,因此会引发异常。插入验证:

if (response_headers.Headers["Location"] != null && response_headers.Headers["Location"].Contains("alted"))
    {
        log("[-] GROUP is " + gr + " closed\r\n");
        return -2;
    }
于 2012-12-03T15:36:54.990 回答
1

您收到该消息是因为您在所有代码周围都有一个 catch everything 块:

catch { log("[?] Can't parse ash and grpId\r\n"); return -1; }

这是一个不好的做法。删除 try/catch 块并让原始异常显示出来。这将有可能看到真正的问题是什么。

于 2012-12-03T15:37:01.573 回答