في الآونة الأخيرة ، أعمل على برنامج صغير يمكنه تسجيل الدخول وإرسال الرسائل تلقائيًا من خلال httpwebrequest. هذا ما رأيته.
1 استخدام نظام ؛
2 using system.Runtime.InteropServices ؛
3 using system.text ؛
4 using system.net ؛
5
6namespace nexplos.nsiter
7 {
8/** //// <summary>
9 /// فئة الطريقة للحصول على ملفات تعريف الارتباط.
10 /// </summary>
11 الطبقة العامة cookiemanger
12 {
13/** /// <summary>
14 /// الحصول على بيانات ملفات تعريف الارتباط من خلال com.
15 /// </summary>
16 /// <param name = url> url الحالي. </param>
17 /// <param name = cookiename> cookiename. </param>
18 /// <param name = cookiedata> المستخدمة لحفظ <see cref = stringbuilder/> مثيل بيانات ملفات تعريف الارتباط. </param>
19 /// <param name = size> حجم ملفات تعريف الارتباط. </param>
20 /// <RESTRANSS> إرجاع <c> TRUE </c> إذا نجحت ، وإلا مرة أخرى <c> false </c>. </returns>
21 [dllimport (winet.dll ، setlasterror = true)]
22 عاما ساكرا انترابوكيوكي (
23 url url ، string cookiename ،
24 StringBuilder Cookiedata ، Ref int size) ؛
25/** //// <summary>
26 /// احصل على التيار <see cref = cookieContainer/مثيل <see cref = uri/>.
27 /// </summary>
28 /// <param name = uri> العنوان الحالي <see cref = uri/>. </param>
29 /// <Returns> the the the the curf = see ceariecontainer/evalue of <see cref = uri/>. </returns>
30 static static static geturicookontainer (uri uri) {
31 ملفات تعريف الارتباط CookiContainer = فارغة ؛
32
33 // تحديد حجم بيانات ملفات تعريف الارتباط.
34 int datasize = 256 ؛
35 StringBuilder cookiedata = new StringBuilder (datasize) ؛
36
37 if (! InternetGetCookie (uri.tostring () ، null ، cookiedata ،
38 مرجع البيانات)) {
39 إذا (datasize <0)
40 عودة لاغية.
41
42 // تأكد من وجود مساحة كافية لاستيعاب بيانات ملفات تعريف الارتباط.
43 cookiedata = new StringBuilder (datasize) ؛
44 if (! InternetGetCookie (uri.tostring () ، null ، cookiedata ،
45 مرجع البيانات)))
46 عودة لاغية ؛
47}
48
49
50 if (cookiedata.length> 0) {
51 ملفات تعريف الارتباط = cookieContainer جديد () ؛
52 ملفات تعريف الارتباط.
53}
54 ملفات تعريف الارتباط الإرجاع ؛
55}
56
57}
58} أليس هذا بسيطًا جدًا؟