日期:2014-05-17 浏览次数:20917 次
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace WinTest
{
class Wininet
{
public const uint INTERNET_OPEN_TYPE_PRECONFIG = 0;
public const uint INTERNET_OPEN_TYPE_DIRECT = 1;
public const uint INTERNET_OPEN_TYPE_GATEWAY = 2;
public const uint INTERNET_OPEN_TYPE_PROXY = 3;
//Service/Command types
public const uint INTERNET_SERVICE_HTTP = 3;
//Internet connection flags
public const uint INTERNET_FLAG_KEEP_CONNECTION = 0x400000;
public const uint INTERNET_FLAG_NO_CACHE_WRITE = 0x4000000;
public const uint INTERNET_FLAG_RELOAD = 0x80000000;
//addheaders flags
public const uint HTTP_ADDREQ_FLAG_ADD_IF_NEW = 0x10000000;
public const uint HTTP_ADDREQ_FLAG_ADD = 0x20000000;
public const uint HTTP_ADDREQ_FLAG_REPLACE = 0x80000000;
public const string HTTP_VERSION = "HTTP/1.1";
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern uint GetLastError();
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern IntPtr InternetOpen(string strAppName, ulong ulAccessType, string strProxy, string strProxyBypass, ulong ulFlags);
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern IntPtr InternetConnect(IntPtr ulSession, string strServer, uint ulPort, string strUser, string strPassword, uint ulService, uint ulFlags, uint ulContext);
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetGetConnectedState(ref uint ulFlags, uint ulReserved);
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetCloseHandle(Int