四:客服端防护HTTP发送请求类

时间:2023-03-09 04:50:05
四:客服端防护HTTP发送请求类
一、源代码:
public class swtDefendOperate
{
private BackgroundWorker backgroundWorker;
//DefendType的值 VerifyUser_Defend_On:开启验证用户的防护
//DefendValue的值 "1"开启 "0"关闭
string DefendType = "", DefendValue = "";
public swtDefendOperate(string defendType, string value)
{
this.DefendType = defendType;
this.DefendValue = value;
this.backgroundWorker = new BackgroundWorker();
this.backgroundWorker.WorkerSupportsCancellation = true;
this.backgroundWorker.DoWork += new DoWorkEventHandler(this.backgroundWorker_DoWork);
this.backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker_RunWorkerCompleted);
this.backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
d7 d = new d7();
d.a(2);
d.a(true);
d.b("sn", t.b().au);
BackgroundWorker worker = sender as BackgroundWorker;
if (worker.CancellationPending)
{
e.Cancel = true;
}
else
{
d.b("defendtype", DefendType);
d.b("defendvalue", DefendValue);
d.a(t.b().af + "oc/DefendSetting.aspx?siteid=" + t.i);
if (d.h())
{
e.Result = d.j();
}
string str = d.a().Headers["r"];
if (str == "ok")
{
e.Result = str;
}
else
{
e.Result = "no data";
}
}

}
catch (Exception exception)
{
eu.a("backgroundWorker1_DoWork:" + exception.ToString());
}
finally
{
}
}

private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!e.Cancelled)
{
if (e.Result.ToString() == "ok")
{
MessageBox.Show("设置成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("设置发生错误,请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}
}
}

二:生成的IL代码
//edit by dyh221 ,商务通防护客服端配置类(发送设置信息或取消设置信到服务器端)
.class public auto ansi beforefieldinit swtDefendOperate
extends [mscorlib]System.Object
{
.field private class [System]System.ComponentModel.BackgroundWorker backgroundWorker
.field private string DefendType
.field private string DefendValue
.method public hidebysig specialname rtspecialname
instance void .ctor(string defendType,
string 'value') cil managed
{
// 代码大小 130 (0x82)
.maxstack 3
IL_0000: ldarg.0
IL_0001: ldstr ""
IL_0006: stfld string swtDefendOperate::DefendType
IL_000b: ldarg.0
IL_000c: ldstr ""
IL_0011: stfld string swtDefendOperate::DefendValue
IL_0016: ldarg.0
IL_0017: call instance void [mscorlib]System.Object::.ctor()
IL_001c: nop
IL_001d: nop
IL_001e: ldarg.0
IL_001f: ldarg.1
IL_0020: stfld string swtDefendOperate::DefendType
IL_0025: ldarg.0
IL_0026: ldarg.2
IL_0027: stfld string swtDefendOperate::DefendValue
IL_002c: ldarg.0
IL_002d: newobj instance void [System]System.ComponentModel.BackgroundWorker::.ctor()
IL_0032: stfld class [System]System.ComponentModel.BackgroundWorker swtDefendOperate::backgroundWorker
IL_0037: ldarg.0
IL_0038: ldfld class [System]System.ComponentModel.BackgroundWorker swtDefendOperate::backgroundWorker
IL_003d: ldc.i4.1
IL_003e: callvirt instance void [System]System.ComponentModel.BackgroundWorker::set_WorkerSupportsCancellation(bool)
IL_0043: nop
IL_0044: ldarg.0
IL_0045: ldfld class [System]System.ComponentModel.BackgroundWorker swtDefendOperate::backgroundWorker
IL_004a: ldarg.0
IL_004b: ldftn instance void swtDefendOperate::backgroundWorker_DoWork(object,
class [System]System.ComponentModel.DoWorkEventArgs)
IL_0051: newobj instance void [System]System.ComponentModel.DoWorkEventHandler::.ctor(object,
native int)
IL_0056: callvirt instance void [System]System.ComponentModel.BackgroundWorker::add_DoWork(class [System]System.ComponentModel.DoWorkEventHandler)
IL_005b: nop
IL_005c: ldarg.0
IL_005d: ldfld class [System]System.ComponentModel.BackgroundWorker swtDefendOperate::backgroundWorker
IL_0062: ldarg.0
IL_0063: ldftn instance void swtDefendOperate::backgroundWorker_RunWorkerCompleted(object,
class [System]System.ComponentModel.RunWorkerCompletedEventArgs)
IL_0069: newobj instance void [System]System.ComponentModel.RunWorkerCompletedEventHandler::.ctor(object,
native int)
IL_006e: callvirt instance void [System]System.ComponentModel.BackgroundWorker::add_RunWorkerCompleted(class [System]System.ComponentModel.RunWorkerCompletedEventHandler)
IL_0073: nop
IL_0074: ldarg.0
IL_0075: ldfld class [System]System.ComponentModel.BackgroundWorker swtDefendOperate::backgroundWorker
IL_007a: callvirt instance void [System]System.ComponentModel.BackgroundWorker::RunWorkerAsync()
IL_007f: nop
IL_0080: nop
IL_0081: ret
} // end of method swtDefendOperate::.ctor

.method private hidebysig instance void
backgroundWorker_DoWork(object sender,
class [System]System.ComponentModel.DoWorkEventArgs e) cil managed
{
// 代码大小 289 (0x121)
.maxstack 4
.locals init ([0] class d7 d,
[1] class [System]System.ComponentModel.BackgroundWorker worker,
[2] string str,
[3] class [mscorlib]System.Exception exception,
[4] bool CS$4$0000)
IL_0000: nop
.try
{
.try
{
IL_0001: nop
IL_0002: newobj instance void d7::.ctor()
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: ldc.i4.2
IL_000a: callvirt instance void d7::a(int32)
IL_000f: nop
IL_0010: ldloc.0
IL_0011: ldc.i4.1
IL_0012: callvirt instance void d7::a(bool)
IL_0017: nop
IL_0018: ldloc.0
IL_0019: ldstr "sn"
IL_001e: call class t t::b()
IL_0023: ldfld string t::au
IL_0028: callvirt instance void d7::b(string,
string)
IL_002d: nop
IL_002e: ldarg.1
IL_002f: isinst [System]System.ComponentModel.BackgroundWorker
IL_0034: stloc.1
IL_0035: ldloc.1
IL_0036: callvirt instance bool [System]System.ComponentModel.BackgroundWorker::get_CancellationPending()
IL_003b: ldc.i4.0
IL_003c: ceq
IL_003e: stloc.s CS$4$0000
IL_0040: ldloc.s CS$4$0000
IL_0042: brtrue.s IL_0053

IL_0044: nop
IL_0045: ldarg.2
IL_0046: ldc.i4.1
IL_0047: callvirt instance void [System]System.ComponentModel.CancelEventArgs::set_Cancel(bool)
IL_004c: nop
IL_004d: nop
IL_004e: br IL_00fb

IL_0053: nop
IL_0054: ldloc.0
IL_0055: ldstr "defendtype"
IL_005a: ldarg.0
IL_005b: ldfld string swtDefendOperate::DefendType
IL_0060: callvirt instance void d7::b(string,
string)
IL_0065: nop
IL_0066: ldloc.0
IL_0067: ldstr "defendvalue"
IL_006c: ldarg.0
IL_006d: ldfld string swtDefendOperate::DefendValue
IL_0072: callvirt instance void d7::b(string,
string)
IL_0077: nop
IL_0078: ldloc.0
IL_0079: call class t t::b()
IL_007e: ldfld string t::af
IL_0083: ldstr "oc/DefendSetting.aspx\?siteid="
IL_0088: ldsfld string t::i
IL_008d: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_0092: callvirt instance string d7::a(string)
IL_0097: pop
IL_0098: ldloc.0
IL_0099: callvirt instance bool d7::h()
IL_009e: ldc.i4.0
IL_009f: ceq
IL_00a1: stloc.s CS$4$0000
IL_00a3: ldloc.s CS$4$0000
IL_00a5: brtrue.s IL_00b6

IL_00a7: nop
IL_00a8: ldarg.2
IL_00a9: ldloc.0
IL_00aa: callvirt instance string d7::j()
IL_00af: callvirt instance void [System]System.ComponentModel.DoWorkEventArgs::set_Result(object)
IL_00b4: nop
IL_00b5: nop
IL_00b6: ldloc.0
IL_00b7: callvirt instance class [System]System.Net.HttpWebResponse d7::a()
IL_00bc: callvirt instance class [System]System.Net.WebHeaderCollection [System]System.Net.WebResponse::get_Headers()
IL_00c1: ldstr "r"
IL_00c6: callvirt instance string [System]System.Collections.Specialized.NameValueCollection::get_Item(string)
IL_00cb: stloc.2
IL_00cc: ldloc.2
IL_00cd: ldstr "ok"
IL_00d2: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_00d7: ldc.i4.0
IL_00d8: ceq
IL_00da: stloc.s CS$4$0000
IL_00dc: ldloc.s CS$4$0000
IL_00de: brtrue.s IL_00ec

IL_00e0: nop
IL_00e1: ldarg.2
IL_00e2: ldloc.2
IL_00e3: callvirt instance void [System]System.ComponentModel.DoWorkEventArgs::set_Result(object)
IL_00e8: nop
IL_00e9: nop
IL_00ea: br.s IL_00fa

IL_00ec: nop
IL_00ed: ldarg.2
IL_00ee: ldstr "no data"
IL_00f3: callvirt instance void [System]System.ComponentModel.DoWorkEventArgs::set_Result(object)
IL_00f8: nop
IL_00f9: nop
IL_00fa: nop
IL_00fb: nop
IL_00fc: leave.s IL_0119

} // end .try
catch [mscorlib]System.Exception
{
IL_00fe: stloc.3
IL_00ff: nop
IL_0100: ldstr "backgroundWorker1_DoWork:"
IL_0105: ldloc.3
IL_0106: callvirt instance string [mscorlib]System.Object::ToString()
IL_010b: call string [mscorlib]System.String::Concat(string,
string)
IL_0110: call void eu::a(string)
IL_0115: nop
IL_0116: nop
IL_0117: leave.s IL_0119

} // end handler
IL_0119: nop
IL_011a: leave.s IL_011f

} // end .try
finally
{
IL_011c: nop
IL_011d: nop
IL_011e: endfinally
} // end handler
IL_011f: nop
IL_0120: ret
} // end of method swtDefendOperate::backgroundWorker_DoWork

.method private hidebysig instance void
backgroundWorker_RunWorkerCompleted(object sender,
class [System]System.ComponentModel.RunWorkerCompletedEventArgs e) cil managed
{
// 代码大小 86 (0x56)
.maxstack 4
.locals init ([0] bool CS$4$0000)
IL_0000: nop
IL_0001: ldarg.2
IL_0002: callvirt instance bool [System]System.ComponentModel.AsyncCompletedEventArgs::get_Cancelled()
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: brtrue.s IL_0055

IL_000b: nop
IL_000c: ldarg.2
IL_000d: callvirt instance object [System]System.ComponentModel.RunWorkerCompletedEventArgs::get_Result()
IL_0012: callvirt instance string [mscorlib]System.Object::ToString()
IL_0017: ldstr "ok"
IL_001c: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0021: ldc.i4.0
IL_0022: ceq
IL_0024: stloc.0
IL_0025: ldloc.0
IL_0026: brtrue.s IL_003f

IL_0028: nop
IL_0029: ldstr bytearray (BE 8B 6E 7F 10 62 9F 52 ) // ..n..b.R
IL_002e: ldstr bytearray (D0 63 3A 79 ) // .c:y
IL_0033: ldc.i4.0
IL_0034: ldc.i4.s 64
IL_0036: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
string,
valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
IL_003b: pop
IL_003c: nop
IL_003d: br.s IL_0054

IL_003f: nop
IL_0040: ldstr bytearray (BE 8B 6E 7F D1 53 1F 75 19 95 EF 8B 0C FF F7 8B // ..n..S.u........
CD 91 D5 8B )
IL_0045: ldstr bytearray (D0 63 3A 79 ) // .c:y
IL_004a: ldc.i4.0
IL_004b: ldc.i4.s 16
IL_004d: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
string,
valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
IL_0052: pop
IL_0053: nop
IL_0054: nop
IL_0055: ret
} // end of method swtDefendOperate::backgroundWorker_RunWorkerCompleted

} // end of class swtDefendOperate