另一个CookieContainer类错误? [英] Another CookieContainer class bug?
问题描述
为了更好的可读性,我编辑了这个。这也是一个不同的问题
目的此代码的一部分是将CookieContainer对象转换为HashTable,以便以后转换为CookieCollection。我为此代码收到错误无法找到变量'm_domainTable'
I edited this for better readability. This is also a different question
The purpose of this code is to convert a CookieContainer object to a HashTable for later conversion to a CookieCollection. I get the error "Cannot find variable 'm_domainTable'" for this code
var cookieJar = new CookieContainer();
cookieJar.Add(new Uri("http://someuri.com"), new Cookie("name", "value", "/path/", ".domain"));
var table = (Hashtable) cookieJar.GetType().InvokeMember("m_domainTable",
BindingFlags.NonPublic |
BindingFlags.GetField |
BindingFlags.Instance,
null,
cookieJar,
new object[] {});
甚至使用此 hack 都能够遍历本地存储的cookie文件。我尝试使用下面建议的代码创建一个新项目,但是我收到错误对象未设置为对象的实例。
The purpose of even using this hack is to be able to cycle through a locally stored cookie file. I tried creating a new project using this code suggested below but I get the error "Object not set to an instance of an Object".
var cookieJar = new CookieContainer();
var table = (Hashtable)cookieJar.GetType()
.GetField("m_domainTable", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(cookieJar);
所以我被卡住了。以前我已经展示了我的SendPost()方法,但由于这个错误只涉及这些代码,我拿出了那个方法。如果您需要更多代码或需要我测试任何东西,请告诉我,因为我很乐意让这个工作。
我的环境设置是使用Mono / .Net的MonoDevelop 4.5使用这些程序集:
So I am stuck. Previously I had shown my SendPost() method but since this error only involves these bits of code I took out that method. If you need any more code or need me to test anything let me know as I would love to get this working.
My enviornment setup is MonoDevelop using Mono / .Net 4.5 using these assemblies:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections;
using System.Web;
推荐答案
已解决。 Mono的CookieContainer类不包含m_domainTable的变量。我想这些假设很糟糕。
Resolved. Mono's CookieContainer class does not contain a variable for "m_domainTable" assumptions are bad I guess.
这篇关于另一个CookieContainer类错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!