我正在尝试从Web浏览器控件切换到http请求以自动执行任务以提高速度.使用此功能,我可以发布数据并接收登录页面,但不会返回任何cookie并将其添加到cookie列表中,因此登录的会话不会传递给下一个请求.
//an example call
test("http://websitename.com/loginpage.php", "username=foo&password=123456");
private string test(string url, string data)
{
string responseFromServer;
byte[] byteArray;
Stream dataStream;
HttpWebRequest request;
HttpWebResponse response;
StreamReader reader;
responseFromServer = string.Empty;
try
{
request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
byteArray = Encoding.UTF8.GetBytes(data);
request.ContentLength = byteArray.Length;
request.CookieContainer = new CookieContainer();
foreach(Cookie a in cookies)
request.CookieContainer.Add(a);
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
response = request.GetResponse() as HttpWebResponse;
foreach(Cookie a in response.Cookies)
cookies.Add(a);
dataStream = response.GetResponseStream();
reader …Run Code Online (Sandbox Code Playgroud) 我使用WebBrowser控件导航到WordPress博客的登录页面.页面加载正常,但每当我尝试从一个线程访问WebBrowser时.我得到一个特定的演员是无效的例外.同样在调试时,一切都冻结了大约5秒钟.调试时,我尝试访问控件.我得到了所有成员变量的错误.
//in constructor of main form
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
this.CheckForIllegalCrossThreadCalls = false;
mainThreadHandle = new Thread(mainThread);
mainThreadHandle.Start();
private void mainThread()
{
wbMain.Navigate("http://example.com/");
//navigating is set to false in the document complete event.
navigating = true;
while (navigating == true)
Thread.Sleep(5000);
try
{
//Where I get the issues
MessageBox.Show(wbMain.DocumentText);
}
catch (Exception e)
{
}
Thread.Sleep(1000);
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试通过设备上下文句柄获取窗口的句柄。我尝试过 WindowFromDC() ,它不断返回空结果。如何从任何设备上下文获取窗口句柄?
我有一个加载到多个进程的DLL.什么是一个干净的方式来沟通这些进程/ dll.发送简单字符串是目标.我宁愿避免sendmessage,file io和发送string命令的地址.