Sådan ser min kode ud, men jeg får fejlmeddelelsen:"Database is locked".
- using System.Data.SQLite;
-
-
- namespace DitNamespaceErMitTerv
- {
- public class Cookies
- {
- private static string GetFireFoxCookiePath()
- {
- var x = Environment.GetFolderPath(
- Environment.SpecialFolder.ApplicationData);
- x += @"\Mozilla\Firefox\Profiles\";
- var di = new DirectoryInfo(x);
- var dir = di.GetDirectories("*.default");
- if (dir.Length != 1)
- return string.Empty;
-
- x += dir[0].Name + @"\" + "cookies.sqlite";
-
- if (!File.Exists(x))
- return string.Empty;
-
- return x;
- }
-
- private static Dictionary<string, CookieContainer> CookieYar = new Dictionary<string, CookieContainer>();
-
- private static CookieContainer GetCookieConatinerForHost(string url)
- {
- var uri = new Uri(url);
- var host = uri.Host.Replace("www.", "");
-
- if (CookieYar.ContainsKey(host))
- return CookieYar[host];
-
-
-
- var cc = new CookieContainer();
- using (var conn = new SQLiteConnection("Data Source=" + GetFireFoxCookiePath()))
- {
- using (var cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select * from moz_cookies where host like '%" + host + "%';";
- conn.Open();
- using (var reader = cmd.ExecuteReader())
- {
- while (reader.Read())
- {
- cc.Add(new Cookie(reader["name"].ToString(), reader["value"].ToString(),
- reader["path"].ToString(), reader["host"].ToString()));
- }
- }
- }
- }
- CookieYar.Add(host, cc);
-
- return cc;
- }
-
- internal static string DownLoadData(string urlToDownload)
- {
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlToDownload);
- req.CookieContainer = GetCookieConatinerForHost("http://www.outwar.com");
- HttpWebResponse response = (HttpWebResponse)req.GetResponse();
- StreamReader strm = new StreamReade
- return strm.ReadToEnd();
- }
-
- internal static string HttpPost(string url, string post, string refer = "")
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.CookieContainer = GetCookieConatinerForHost(url);
- request.Method = "POST";
- request.Referer = refer;
-
- byte[] postBytes = Encoding.ASCII.GetBytes(post);
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = postBytes.Length;
-
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(postBytes, 0, postBytes.Length);
- requestStream.Close();
-
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream());
-
- return sr.ReadToEnd();
- }
- }
- }
Indlæg senest redigeret d. 26.04.2011 20:10 af Bruger #14181