万飞

潇洒的活着,利用技术为自己创造财富

导航

利用winform管理网站

Posted on 2010-04-11 10:45  万飞  阅读(148)  评论(0)    收藏  举报

  有时候我们的应用程序需要像QQ那样打开一个按钮就自动登录网站

  QQ好像是通过activex控件太判断的

 

代码
using System;
using System.Text;
using System.Runtime.InteropServices;


class TestCookie
{

[DllImport(
"wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool InternetGetCookie(
string lpszUrlName,
string lpszCookieName,
StringBuilder lpszCookieData,
ref uint lpdwSize
);


[DllImport(
"kernel32.dll")]
internal static extern Int32 GetLastError();

public static string GetCookie(string url)
{
StringBuilder sb
= new StringBuilder(1000);
uint size = 1000;
bool bGood = InternetGetCookie(url,"", sb,ref size);
if (!bGood)
Console.WriteLine(
"Error code:{0}", GetLastError());

return sb.ToString();
}


public static void Main()
{
Console.WriteLine(GetCookie(
"http://expert.csdn.net"));
}