|
// sample function that takes in a destination server, POST data, and custom HTTP request headers |
|
private string SendData(string dst, byte[] postData, string customHeaders) |
|
{ |
|
Type com_type = Type.GetTypeFromCLSID(new Guid("0002DF01-0000-0000-C000-000000000046")); |
|
object IE = Activator.CreateInstance(com_type); |
|
|
|
object[] falseArr = new object[] { false }; |
|
object[] trueArr = new object[] { true }; |
|
com_type.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, IE, falseArr); |
|
com_type.InvokeMember("Silent", System.Reflection.BindingFlags.SetProperty, null, IE, trueArr); |
|
|
|
object URL = dst; |
|
object flag = 14; |
|
object empty = 0; |
|
object pd = postData; |
|
|
|
object headers = ""; |
|
if (customHeaders != "") { |
|
foreach (string header in customHeaders.Split('|')) |
|
{ |
|
headers += String.Format("{0}: {1}\r\n", header.Split(':')[0], header.Split(':')[1]); |
|
} |
|
} |
|
|
|
object[] oParms = new Object[] { dst, flag, empty, pd, headers }; |
|
com_type.InvokeMember("Navigate2", System.Reflection.BindingFlags.InvokeMethod, null, IE, oParms); |
|
while ((bool)(com_type.InvokeMember("Busy", System.Reflection.BindingFlags.GetProperty, null, IE, null)) == true) |
|
{ |
|
System.Threading.Thread.Sleep(100); |
|
} |
|
|
|
object document = com_type.InvokeMember("Document", System.Reflection.BindingFlags.GetProperty, null, IE, null); |
|
object body = document.GetType().InvokeMember("body", System.Reflection.BindingFlags.GetProperty, null, document, null); |
|
object content = body.GetType().InvokeMember("outerHTML", System.Reflection.BindingFlags.GetProperty, null, body, null); |
|
com_type.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, IE, null); |
|
|
|
return content.ToString(); |
|
} |