public static void CallPrivateMethod(object instance, string name, params object[] param) { BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic; Type type = instance.GetType(); MethodInfo method = type.GetMethod(name, flag); method.Invoke(instance, param); }
转自 https://segmentfault.com/q/1010000007608935?_ea=1398469
var request = (HttpWebRequest)WebRequest.Create("https://"); CallPrivateMethod(request, "SetSpecialHeaders", "AAAAAAAA", DateTime.Now.ToString("R"));