123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace HPSocketCS
- {
- public static class ____LinqEx
- {
- public static byte LOBYTE(this HttpVersion version)
- {
- return (byte)((ushort)version & 0xff);
- }
- public static byte HIBYTE(this HttpVersion version)
- {
- return (byte)((ushort)version >> 8);//高8位
- }
- public static string ToString(this HttpMethod method)
- {
- var fi = method.GetType().GetField(method.ToString());
- var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
- return (attributes.Length > 0) ? attributes[0].Description : method.ToString();
- }
- }
- public enum WSOpcode : byte
- {
- Cont = 0x0,
- Text = 0x1,
- Binary = 0x2,
- Close = 0x8,
- Ping = 0x9,
- Pong = 0xa,
- }
- public enum WSReserved : byte
- {
- Off = 0x0,
- On = 0x1
- }
- public class WSMessageState
- {
- public bool Final { get; set; }
- public WSReserved Reserved { get; set; }
- public WSOpcode OperationCode { get; set; }
- public byte[] Mask { get; set; }
- public ulong BodyLen { get; set; }
- public ulong BodyRemain { get; set; }
- }
- /// <summary>
- /// http版本号
- /// </summary>
- public enum HttpVersion
- {
- /// <summary>
- /// http 1.0
- /// </summary>
- V1_0 = 1,
- /// <summary>
- /// http 1.1
- /// </summary>
- v1_1 = 257,
- }
- /// <summary>
- /// URL 域
- /// HTTP 请求行中 URL 段位的域定义
- /// </summary>
- public enum HttpUrlField
- {
- Schema = 0,
- Host = 1,
- Port = 2,
- Path = 3,
- QueryString = 4,
- Fragment = 5,
- UserInfo = 6,
- /// <summary>
- /// Field Count
- /// </summary>
- Max = 7,
- }
- /// <summary>
- /// HTTP 解析结果标识
- /// 指示 HTTP 解析器是否继续执行解析操作
- /// </summary>
- public enum HttpParseResult
- {
- /// <summary>
- /// 终止解析,断开连接
- /// </summary>
- Error = -1,
- /// <summary>
- /// 继续解析
- /// </summary>
- Ok = 0,
- }
- /// <summary>
- /// HTTP 解析结果标识
- /// 指示 HTTP 解析器是否继续执行解析操作
- /// </summary>
- public enum HttpParseResultEx
- {
- /// <summary>
- /// 终止解析,断开连接
- /// </summary>
- Error = -1,
- /// <summary>
- /// 继续解析
- /// </summary>
- Ok = 0,
- /// <summary>
- /// 跳过当前请求 BODY
- /// </summary>
- SkipBody = 1,
- /// <summary>
- /// 升级协议
- /// </summary>
- Upgrade = 2,
- }
- public enum HttpUpgradeType
- {
- /// <summary>
- /// 没有升级
- /// </summary>
- None = 0,
- /// <summary>
- /// WebSocket
- /// </summary>
- WebSocket = 1,
- /// <summary>
- /// HTTP 隧道
- /// </summary>
- HttpTunnel = 2,
- /// <summary>
- /// 未知类型
- /// </summary>
- Unknown = -1,
- }
- public enum HttpStatusCode
- {
- Continue = 100,
- SwitchingProtocols = 101,
- Processing = 102,
- Ok = 200,
- Created = 201,
- Accepted = 202,
- NonAuthoritativeInformation = 203,
- NoContent = 204,
- ResetContent = 205,
- PartialContent = 206,
- MultiStatus = 207,
- MultipleChoices = 300,
- MovedPermanently = 301,
- MovedTemporarily = 302,
- SeeOther = 303,
- NotModified = 304,
- UseProxy = 305,
- SwitchProxy = 306,
- TemporaryRedirect = 307,
- BadRequest = 400,
- Unauthorized = 401,
- PaymentRequired = 402,
- Forbidden = 403,
- NotFound = 404,
- MethodNotAllowed = 405,
- NotAcceptable = 406,
- ProxyAuthenticationRequired = 407,
- RequestTimeout = 408,
- Conflict = 409,
- Gone = 410,
- LengthRequired = 411,
- PreconditionFailed = 412,
- RequestEntityTooLarge = 413,
- RequestUriTooLong = 414,
- UnsupportedMediaType = 415,
- RequestedRangeNotSatisfiable = 416,
- ExpectationFailed = 417,
- UnprocessableEntity = 422,
- Locked = 423,
- FailedDependency = 424,
- UnorderedCollection = 435,
- UpgradeRequired = 426,
- RetryWith = 449,
- InternalServerError = 500,
- NotImplemented = 501,
- BadGateway = 502,
- ServiceUnavailable = 503,
- GatewayTimeout = 504,
- HttpVersionNotSupported = 505,
- VariantAlsoNegotiates = 506,
- InsufficientStorage = 507,
- BandwidthLimitExceeded = 509,
- NotExtended = 510,
- UnparseableResponseHeaders = 600,
- }
- /// <summary>
- /// HttpMethod
- /// </summary>
- public enum HttpMethod
- {
- [Description("GET")]
- Get,
- [Description("POST")]
- Post,
- [Description("PUT")]
- Put,
- [Description("PATCH")]
- Patch,
- [Description("DELETE")]
- Delete,
- [Description("HEAD")]
- Head,
- [Description("TRACE")]
- Trace,
- [Description("OPTIONS")]
- Options,
- [Description("CONNECT")]
- Connect,
- }
- /// <summary>
- /// Name/Value 结构体
- /// 字符串名值对结构体
- /// </summary>
- public struct TNVPair
- {
- [MarshalAs(UnmanagedType.LPStr)]
- public string Name;
- [MarshalAs(UnmanagedType.LPStr)]
- public string Value;
- }
- public struct TCookie
- {
- [MarshalAs(UnmanagedType.LPStr)]
- public string Name;
- [MarshalAs(UnmanagedType.LPStr)]
- public string Value;
- }
- public struct THeader
- {
- [MarshalAs(UnmanagedType.LPStr)]
- public string Name;
- [MarshalAs(UnmanagedType.LPStr)]
- public string Value;
- }
- public struct THeaderForIntPtr
- {
- public IntPtr Name;
- public IntPtr Value;
- }
- /// <summary>
- /// http事件
- /// </summary>
- public class HttpEvent
- {
- public delegate HttpParseResult OnMessageBeginEventHandler(IntPtr connId);
- public delegate HttpParseResult OnHeaderEventHandler(IntPtr connId, string name, string value);
- public delegate HttpParseResultEx OnHeadersCompleteEventHandler(IntPtr connId);
- public delegate HttpParseResult OnPointerDataBodyEventHandler(IntPtr connId, IntPtr pData, int length);
- public delegate HttpParseResult OnBodyEventHandler(IntPtr connId, byte[] bytes);
- public delegate HttpParseResult OnChunkHeaderEventHandler(IntPtr connId, int length);
- public delegate HttpParseResult OnChunkCompleteEventHandler(IntPtr connId);
- public delegate HttpParseResult OnMessageCompleteEventHandler(IntPtr connId);
- public delegate HttpParseResult OnUpgradeEventHandler(IntPtr connId, HttpUpgradeType upgradeType);
- public delegate HttpParseResult OnParseErrorEventHandler(IntPtr connId, int errorCode, string errorDesc);
- }
- /// <summary>
- /// http server 事件
- /// </summary>
- public class HttpServerEvent : HttpEvent
- {
- public delegate HttpParseResult OnRequestLineEventHandler(IntPtr connId, string method, string url);
- }
- /// <summary>
- /// http cilent 事件
- /// </summary>
- public class HttpClientEvent : HttpEvent
- {
- public delegate HttpParseResult OnStatusLineEventHandler(IntPtr connId, ushort statusCode, string desc);
- }
- /// <summary>
- /// http agent 事件
- /// </summary>
- public class HttpAgentEvent : HttpClientEvent
- {
- }
- /// <summary>
- /// websocket 事件
- /// </summary>
- public class WebSocketEvent : HttpEvent
- {
- public delegate HandleResult OnWSMessageHeaderEventHandler(IntPtr connId, bool final, byte reserved, byte operationCode, byte[] mask, ulong bodyLength);
- public delegate HandleResult OnPointerWSMessageBodyEventHandler(IntPtr connId, IntPtr pData, int length);
- public delegate HandleResult OnWSMessageBodyEventHandler(IntPtr connId, byte[] data);
- public delegate HandleResult OnWSMessageCompleteEventHandler(IntPtr connId);
- }
- public class HttpSdk
- {
- /****************************************************/
- /******************* HTTP 回调函数 *******************/
- /* Agent & Server & Clent */
- public delegate HttpParseResult OnMessageBegin(IntPtr pSender, IntPtr connId);
- public delegate HttpParseResult OnHeader(IntPtr pSender, IntPtr connId, string lpszName, string lpszValue);
- public delegate HttpParseResultEx OnHeadersComplete(IntPtr pSender, IntPtr connId);
- public delegate HttpParseResult OnBody(IntPtr pSender, IntPtr connId, IntPtr pData, int iLength);
- public delegate HttpParseResult OnChunkHeader(IntPtr pSender, IntPtr connId, int iLength);
- public delegate HttpParseResult OnChunkComplete(IntPtr pSender, IntPtr connId);
- public delegate HttpParseResult OnMessageComplete(IntPtr pSender, IntPtr connId);
- public delegate HttpParseResult OnUpgrade(IntPtr pSender, IntPtr connId, HttpUpgradeType enUpgradeType);
- public delegate HttpParseResult OnParseError(IntPtr pSender, IntPtr connId, int iErrorCode, string lpszErrorDesc);
- /* Server */
- public delegate HttpParseResult OnRequestLine(IntPtr pSender, IntPtr connId, string lpszMethod, string lpszUrl);
- /* Agent & Client */
- public delegate HttpParseResult OnStatusLine(IntPtr pSender, IntPtr connId, ushort usStatusCode, string lpszDesc);
- /* WebSocket */
- public delegate HandleResult OnWSMessageHeader(IntPtr pSender, IntPtr dwConnID, bool bFinal, byte iReserved, byte iOperationCode, byte[] lpszMask, ulong ullBodyLen);
- public delegate HandleResult OnWSMessageBody(IntPtr pSender, IntPtr dwConnID, IntPtr pData, int length);
- public delegate HandleResult OnWSMessageComplete(IntPtr pSender, IntPtr dwConnID);
- /****************************************************/
- /***************** HTTP 对象创建函数 *****************/
- /// <summary>
- /// 创建 HP_HttpServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpServer(IntPtr pListener);
- /// <summary>
- /// 创建 HP_HttpAgent 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpAgent(IntPtr pListener);
- /// <summary>
- /// 创建 HP_HttpClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpClient(IntPtr pListener);
- /// <summary>
- /// 创建 HP_HttpSyncClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpSyncClient(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_HttpServer 对象
- /// </summary>
- /// <param name="pServer"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpServer(IntPtr pServer);
- /// <summary>
- /// 销毁 HP_HttpAgent 对象
- /// </summary>
- /// <param name="pAgent"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpAgent(IntPtr pAgent);
- /// <summary>
- /// 销毁 HP_HttpClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpClient(IntPtr pClient);
- /// <summary>
- /// 销毁 HP_HttpSyncClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpSyncClient(IntPtr pClient);
- /// <summary>
- /// 创建 HP_HttpServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpServerListener();
- /// <summary>
- /// 创建 HP_HttpAgentListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpAgentListener();
- /// <summary>
- /// 创建 HP_HttpClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_HttpClientListener();
- /// <summary>
- /// 销毁 HP_HttpServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_HttpAgentListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpAgentListener(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_HttpClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_HttpClientListener(IntPtr pListener);
- /**********************************************************************************/
- /*************************** HTTP Server 回调函数设置方法 **************************/
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnMessageBegin(IntPtr pListener, OnMessageBegin fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnRequestLine(IntPtr pListener, OnRequestLine fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnHeader(IntPtr pListener, OnHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnHeadersComplete(IntPtr pListener, OnHeadersComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnBody(IntPtr pListener, OnBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnChunkHeader(IntPtr pListener, OnChunkHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnChunkComplete(IntPtr pListener, OnChunkComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnMessageComplete(IntPtr pListener, OnMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnUpgrade(IntPtr pListener, OnUpgrade fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnParseError(IntPtr pListener, OnParseError fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnWSMessageHeader(IntPtr pListener, OnWSMessageHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnWSMessageBody(IntPtr pListener, OnWSMessageBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnWSMessageComplete(IntPtr pListener, OnWSMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnPrepareListen(IntPtr pListener, Sdk.OnPrepareListen fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnAccept(IntPtr pListener, Sdk.OnAccept fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnHandShake(IntPtr pListener, Sdk.OnHandShake fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnReceive(IntPtr pListener, Sdk.OnReceive fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnSend(IntPtr pListener, Sdk.OnSend fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnClose(IntPtr pListener, Sdk.OnClose fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpServer_OnShutdown(IntPtr pListener, Sdk.OnShutdown fn);
- /**********************************************************************************/
- /**************************** HTTP Agent 回调函数设置方法 **************************/
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnMessageBegin(IntPtr pListener, OnMessageBegin fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnStatusLine(IntPtr pListener, OnStatusLine fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnHeader(IntPtr pListener, OnHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnHeadersComplete(IntPtr pListener, OnHeadersComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnBody(IntPtr pListener, OnBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnChunkHeader(IntPtr pListener, OnChunkHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnChunkComplete(IntPtr pListener, OnChunkComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnMessageComplete(IntPtr pListener, OnMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnUpgrade(IntPtr pListener, OnUpgrade fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnParseError(IntPtr pListener, OnParseError fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnWSMessageHeader(IntPtr pListener, OnWSMessageHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnWSMessageBody(IntPtr pListener, OnWSMessageBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnWSMessageComplete(IntPtr pListener, OnWSMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnPrepareConnect(IntPtr pListener, Sdk.OnPrepareConnect fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnConnect(IntPtr pListener, Sdk.OnConnect fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnHandShake(IntPtr pListener, Sdk.OnHandShake fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnReceive(IntPtr pListener, Sdk.OnReceive fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnSend(IntPtr pListener, Sdk.OnSend fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnClose(IntPtr pListener, Sdk.OnClose fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpAgent_OnShutdown(IntPtr pListener, Sdk.OnShutdown fn);
- /**********************************************************************************/
- /*************************** HTTP Client 回调函数设置方法 **************************/
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnMessageBegin(IntPtr pListener, OnMessageBegin fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnStatusLine(IntPtr pListener, OnStatusLine fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnHeader(IntPtr pListener, OnHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnHeadersComplete(IntPtr pListener, OnHeadersComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnBody(IntPtr pListener, OnBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnChunkHeader(IntPtr pListener, OnChunkHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnChunkComplete(IntPtr pListener, OnChunkComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnMessageComplete(IntPtr pListener, OnMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnUpgrade(IntPtr pListener, OnUpgrade fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnParseError(IntPtr pListener, OnParseError fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnWSMessageHeader(IntPtr pListener, OnWSMessageHeader fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnWSMessageBody(IntPtr pListener, OnWSMessageBody fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnWSMessageComplete(IntPtr pListener, OnWSMessageComplete fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnPrepareConnect(IntPtr pListener, Sdk.OnPrepareConnect fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnConnect(IntPtr pListener, Sdk.OnConnect fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnHandShake(IntPtr pListener, Sdk.OnHandShake fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnReceive(IntPtr pListener, Sdk.OnReceive fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnSend(IntPtr pListener, Sdk.OnSend fn);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_HttpClient_OnClose(IntPtr pListener, Sdk.OnClose fn);
- /**************************************************************************/
- /***************************** Server 操作方法 *****************************/
- /*
- * 名称:回复请求
- * 描述:向客户端回复 HTTP 请求
- *
- * 参数: dwConnID -- 连接 ID
- * usStatusCode -- HTTP 状态码
- * lpszDesc -- HTTP 状态描述
- * lpHeaders -- 回复请求头
- * iHeaderCount -- 回复请求头数量
- * pData -- 回复请求体
- * iLength -- 回复请求体长度
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_SendResponse(IntPtr pServer, IntPtr dwConnID, ushort usStatusCode, string lpszDesc, THeader[] lpHeaders, int iHeaderCount, byte[] pData, int iLength);
- /*
- /*
- * 名称:发送本地文件
- * 描述:向指定连接发送 4096 KB 以下的小文件
- *
- * 参数: dwConnID -- 连接 ID
- * lpszFileName -- 文件路径
- * usStatusCode -- HTTP 状态码
- * lpszDesc -- HTTP 状态描述
- * lpHeaders -- 回复请求头
- * iHeaderCount -- 回复请求头数量
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_SendLocalFile(IntPtr pServer, IntPtr dwConnID, string lpszFileName, ushort usStatusCode, string lpszDesc, THeader[] lpHeaders, int iHeaderCount);
- /*
- * 名称:发送 WebSocket 消息
- * 描述:向对端端发送 WebSocket 消息
- *
- * 参数: dwConnID -- 连接 ID
- * bFinal -- 是否结束帧
- * iReserved -- RSV1/RSV2/RSV3 各 1 位
- * iOperationCode -- 操作码:0x0 - 0xF
- * lpszMask -- 掩码(nullptr 或 4 字节掩码,如果为 nullptr 则没有掩码)
- * pData -- 消息体数据缓冲区
- * iLength -- 消息体数据长度
- * ullBodyLen -- 消息总长度
- * ullBodyLen = 0 -> 消息总长度为 iLength
- * ullBodyLen = iLength -> 消息总长度为 ullBodyLen
- * ullBodyLen > iLength -> 消息总长度为 ullBodyLen,后续消息体长度为 ullBOdyLen - iLength,后续消息体通过底层方法 Send() / SendPackets() 发送
- * ullBodyLen < iLength -> 错误参数,发送失败
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_SendWSMessage(IntPtr pServer, IntPtr dwConnID, bool bFinal, WSReserved iReserved, WSOpcode iOperationCode, byte[] lpszMask, IntPtr pData, int iLength, ulong ullBodyLen);
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_SendWSMessage(IntPtr pServer, IntPtr dwConnID, bool bFinal, WSReserved iReserved, WSOpcode iOperationCode, byte[] lpszMask, byte[] pdata, int iLength, ulong ullBodyLen);
- /*
- * 名称:释放连接
- * 描述:把连接放入释放队列,等待某个时间(通过 SetReleaseDelay() 设置)关闭连接
- *
- * 参数: dwConnID -- 连接 ID
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_Release(IntPtr pServer, IntPtr dwConnID);
- /*
- * 名称:启动 HTTP 通信
- * 描述:当通信组件设置为非自动启动 HTTP 通信时,需要调用本方法启动 HTTP 通信
- *
- * 返回值: TRUE -- 成功
- * FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_StartHttp(IntPtr pServer, IntPtr dwConnID);
- /******************************************************************************/
- /***************************** Server 属性访问方法 *****************************/
- /* 设置连接释放延时(默认:3000 毫秒) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpServer_SetReleaseDelay(IntPtr pServer, uint dwReleaseDelay);
- /* 获取连接释放延时 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_HttpServer_GetReleaseDelay(IntPtr pServer);
- /* 获取请求行 URL 域掩码(URL 域参考:EnHttpUrlField) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpServer_GetUrlFieldSet(IntPtr pServer, IntPtr dwConnID);
- /* 获取某个 URL 域值 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetUrlField(IntPtr pServer, IntPtr dwConnID, HttpUrlField enField);
- /* 获取请求方法 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetMethod(IntPtr pServer, IntPtr dwConnID);
- /* 设置本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpServer_SetLocalVersion(IntPtr pServer, HttpVersion usVersion);
- /* 获取本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpVersion HP_HttpServer_GetLocalVersion(IntPtr pServer);
- /* 检查是否升级协议 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_IsUpgrade(IntPtr pServer, IntPtr dwConnID);
- /* 检查是否有 Keep-Alive 标识 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_IsKeepAlive(IntPtr pServer, IntPtr dwConnID);
- /* 获取协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpServer_GetVersion(IntPtr pServer, IntPtr dwConnID);
- /* 获取主机 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetHost(IntPtr pServer, IntPtr dwConnID);
- /* 获取内容长度 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern long HP_HttpServer_GetContentLength(IntPtr pServer, IntPtr dwConnID);
- /* 获取内容类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetContentType(IntPtr pServer, IntPtr dwConnID);
- /* 获取内容编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetContentEncoding(IntPtr pServer, IntPtr dwConnID);
- /* 获取传输编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpServer_GetTransferEncoding(IntPtr pServer, IntPtr dwConnID);
- /* 获取协议升级类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpUpgradeType HP_HttpServer_GetUpgradeType(IntPtr pServer, IntPtr dwConnID);
- /* 获取解析错误代码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpServer_GetParseErrorCode(IntPtr pServer, IntPtr dwConnID, ref IntPtr lpszErrorDesc);
- /* 获取某个请求头(单值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetHeader(IntPtr pServer, IntPtr dwConnID, string lpszName, ref IntPtr lpszValue);
- /* 获取某个请求头(多值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetHeaders(IntPtr pServer, IntPtr dwConnID, string lpszName, IntPtr[] lpszValue, ref uint pdwCount);
- /* 获取所有请求头 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetAllHeaders(IntPtr pServer, IntPtr dwConnID, IntPtr lpHeaders, ref uint pdwCount);
- /* 获取所有请求头名称 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetAllHeaderNames(IntPtr pServer, IntPtr dwConnID, IntPtr[] lpszName, ref uint pdwCount);
- /* 获取 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetCookie(IntPtr pServer, IntPtr dwConnID, string lpszName, ref IntPtr lpszValue);
- /* 获取所有 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetAllCookies(IntPtr pServer, IntPtr dwConnID, IntPtr lpCookies, ref uint pdwCount);
- /* 获取当前 WebSocket 消息状态,传入 nullptr 则不获取相应字段 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_GetWSMessageState(IntPtr pServer, IntPtr dwConnID, ref bool lpbFinal, ref WSReserved lpiReserved, ref WSOpcode lpiOperationCode, ref IntPtr lpszMask, ref ulong lpullBodyLen, ref ulong lpullBodyRemain);
- /* 设置 HTTP 启动方式(默认:TRUE,自动启动) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpServer_SetHttpAutoStart(IntPtr pServer, bool bAutoStart);
- /* 获取 HTTP 启动方式 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpServer_IsHttpAutoStart(IntPtr pServer);
- /**************************************************************************/
- /***************************** Agent 操作方法 ******************************/
- /*
- * 名称:发送请求
- * 描述:向服务端发送 HTTP 请求
- *
- * 参数: dwConnID -- 连接 ID
- * lpszMethod -- 请求方法
- * lpszPath -- 请求路径
- * lpHeaders -- 请求头
- * iHeaderCount -- 请求头数量
- * pBody -- 请求体
- * iLength -- 请求体长度
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendRequest(IntPtr pAgent, IntPtr dwConnID, string lpszMethod, string lpszPath, THeader[] lpHeaders, int iHeaderCount, byte[] pData, int iLength);
- /*
- * 名称:发送本地文件
- * 描述:向指定连接发送 4096 KB 以下的小文件
- *
- * 参数: dwConnID -- 连接 ID
- * lpszFileName -- 文件路径
- * lpszMethod -- 请求方法
- * lpszPath -- 请求路径
- * lpHeaders -- 请求头
- * iHeaderCount -- 请求头数量
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendLocalFile(IntPtr pAgent, IntPtr dwConnID, string lpszFileName, string lpszMethod, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 POST 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendPost(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 PUT 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendPut(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 PATCH 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendPatch(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 GET 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendGet(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 DELETE 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendDelete(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 HEAD 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendHead(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 TRACE 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendTrace(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 OPTIONS 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendOptions(IntPtr pAgent, IntPtr dwConnID, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 CONNECT 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendConnect(IntPtr pAgent, IntPtr dwConnID, string lpszHost, THeader[] lpHeaders, int iHeaderCount);
- /*
- * 名称:发送 WebSocket 消息
- * 描述:向对端端发送 WebSocket 消息
- *
- * 参数: dwConnID -- 连接 ID
- * bFinal -- 是否结束帧
- * iReserved -- RSV1/RSV2/RSV3 各 1 位
- * iOperationCode -- 操作码:0x0 - 0xF
- * lpszMask -- 掩码(nullptr 或 4 字节掩码,如果为 nullptr 则没有掩码)
- * pData -- 消息体数据缓冲区
- * iLength -- 消息体数据长度
- * ullBodyLen -- 消息总长度
- * ullBodyLen = 0 -> 消息总长度为 iLength
- * ullBodyLen = iLength -> 消息总长度为 ullBodyLen
- * ullBodyLen > iLength -> 消息总长度为 ullBodyLen,后续消息体长度为 ullBOdyLen - iLength,后续消息体通过底层方法 Send() / SendPackets() 发送
- * ullBodyLen < iLength -> 错误参数,发送失败
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_SendWSMessage(IntPtr pAgent, IntPtr dwConnID, bool bFinal, byte iReserved, byte iOperationCode, byte[] lpszMask, byte[] pData, int iLength, ulong ullBodyLen);
- /*
- * 名称:启动 HTTP 通信
- * 描述:当通信组件设置为非自动启动 HTTP 通信时,需要调用本方法启动 HTTP 通信
- *
- * 返回值: TRUE -- 成功
- * FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_StartHttp(IntPtr pAgent, IntPtr dwConnID);
- /******************************************************************************/
- /***************************** Agent 属性访问方法 ******************************/
- /* 获取 HTTP 状态码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpAgent_GetStatusCode(IntPtr pAgent, IntPtr dwConnID);
- /* 设置本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpAgent_SetLocalVersion(IntPtr pAgent, HttpVersion usVersion);
- /* 获取本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpVersion HP_HttpAgent_GetLocalVersion(IntPtr pAgent);
- /* 检查是否升级协议 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_IsUpgrade(IntPtr pAgent, IntPtr dwConnID);
- /* 检查是否有 Keep-Alive 标识 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_IsKeepAlive(IntPtr pAgent, IntPtr dwConnID);
- /* 获取协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpAgent_GetVersion(IntPtr pAgent, IntPtr dwConnID);
- /* 获取内容长度 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern long HP_HttpAgent_GetContentLength(IntPtr pAgent, IntPtr dwConnID);
- /* 获取内容类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpAgent_GetContentType(IntPtr pAgent, IntPtr dwConnID);
- /* 获取内容编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpAgent_GetContentEncoding(IntPtr pAgent, IntPtr dwConnID);
- /* 获取传输编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpAgent_GetTransferEncoding(IntPtr pAgent, IntPtr dwConnID);
- /* 获取协议升级类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpUpgradeType HP_HttpAgent_GetUpgradeType(IntPtr pAgent, IntPtr dwConnID);
- /* 获取解析错误代码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpAgent_GetParseErrorCode(IntPtr pAgent, IntPtr dwConnID, ref IntPtr lpszErrorDesc);
- /* 获取某个请求头(单值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetHeader(IntPtr pAgent, IntPtr dwConnID, string lpszName, ref IntPtr lpszValue);
- /* 获取某个请求头(多值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetHeaders(IntPtr pAgent, IntPtr dwConnID, string lpszName, IntPtr[] lpszValue, ref uint pdwCount);
- /* 获取所有请求头 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetAllHeaders(IntPtr pAgent, IntPtr dwConnID, IntPtr lpHeaders, ref uint pdwCount);
- /* 获取所有请求头名称 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetAllHeaderNames(IntPtr pAgent, IntPtr dwConnID, IntPtr[] lpszName, ref uint pdwCount);
- /* 设置是否使用 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpAgent_SetUseCookie(IntPtr pAgent, bool bUseCookie);
- /* 检查是否使用 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_IsUseCookie(IntPtr pAgent);
- /* 获取 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetCookie(IntPtr pAgent, IntPtr dwConnID, string lpszName, ref IntPtr lpszValue);
- /* 获取所有 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetAllCookies(IntPtr pAgent, IntPtr dwConnID, IntPtr lpCookies, ref uint pdwCount);
- /* 获取当前 WebSocket 消息状态,传入 nullptr 则不获取相应字段 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_GetWSMessageState(IntPtr pAgent, IntPtr dwConnID, ref bool lpbFinal, ref byte lpiReserved, ref byte lpiOperationCode, ref IntPtr lpszMask, ref ulong lpullBodyLen, ref ulong lpullBodyRemain);
- /* 设置 HTTP 启动方式(默认:TRUE,自动启动) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpAgent_SetHttpAutoStart(IntPtr pAgent, bool bAutoStart);
- /* 获取 HTTP 启动方式 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpAgent_IsHttpAutoStart(IntPtr pAgent);
- /**************************************************************************/
- /***************************** Client 操作方法 *****************************/
- /*
- * 名称:发送请求
- * 描述:向服务端发送 HTTP 请求
- *
- * 参数: lpszMethod -- 请求方法
- * lpszPath -- 请求路径
- * lpHeaders -- 请求头
- * iHeaderCount -- 请求头数量
- * pBody -- 请求体
- * iLength -- 请求体长度
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendRequest(IntPtr pClient, string lpszMethod, string lpszPath, THeader[] lpHeaders, int iHeaderCount, byte[] pBody, int iLength);
- /*
- * 名称:发送本地文件
- * 描述:向指定连接发送 4096 KB 以下的小文件
- *
- * 参数: dwConnID -- 连接 ID
- * lpszFileName -- 文件路径
- * lpszMethod -- 请求方法
- * lpszPath -- 请求路径
- * lpHeaders -- 请求头
- * iHeaderCount -- 请求头数量
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendLocalFile(IntPtr pClient, string lpszFileName, string lpszMethod, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 POST 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendPost(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 PUT 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendPut(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 PATCH 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendPatch(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount, string pBody, int iLength);
- /* 发送 GET 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendGet(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 DELETE 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendDelete(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 HEAD 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendHead(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 TRACE 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendTrace(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 OPTIONS 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendOptions(IntPtr pClient, string lpszPath, THeader[] lpHeaders, int iHeaderCount);
- /* 发送 CONNECT 请求 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendConnect(IntPtr pClient, string lpszHost, THeader[] lpHeaders, int iHeaderCount);
- /*
- * 名称:发送 WebSocket 消息
- * 描述:向对端端发送 WebSocket 消息
- *
- * 参数: bFinal -- 是否结束帧
- * iReserved -- RSV1/RSV2/RSV3 各 1 位
- * iOperationCode -- 操作码:0x0 - 0xF
- * lpszMask -- 掩码(nullptr 或 4 字节掩码,如果为 nullptr 则没有掩码)
- * pData -- 消息体数据缓冲区
- * iLength -- 消息体数据长度
- * ullBodyLen -- 消息总长度
- * ullBodyLen = 0 -> 消息总长度为 iLength
- * ullBodyLen = iLength -> 消息总长度为 ullBodyLen
- * ullBodyLen > iLength -> 消息总长度为 ullBodyLen,后续消息体长度为 ullBOdyLen - iLength,后续消息体通过底层方法 Send() / SendPackets() 发送
- * ullBodyLen < iLength -> 错误参数,发送失败
- * 返回值: TRUE -- 成功
- * FALSE -- 失败
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_SendWSMessage(IntPtr pClient, bool bFinal, byte iReserved, byte iOperationCode, byte[] lpszMask, byte[] pData, int iLength, ulong ullBodyLen);
- /*
- * 名称:启动 HTTP 通信
- * 描述:当通信组件设置为非自动启动 HTTP 通信时,需要调用本方法启动 HTTP 通信
- *
- * 返回值: TRUE -- 成功
- * FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
- */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_StartHttp(IntPtr pClient);
- /******************************************************************************/
- /***************************** Client 属性访问方法 *****************************/
- /* 获取 HTTP 状态码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpClient_GetStatusCode(IntPtr pClient);
- /* 设置本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpClient_SetLocalVersion(IntPtr pClient, HttpVersion usVersion);
- /* 获取本地协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpVersion HP_HttpClient_GetLocalVersion(IntPtr pClient);
- /* 检查是否升级协议 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_IsUpgrade(IntPtr pClient);
- /* 检查是否有 Keep-Alive 标识 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_IsKeepAlive(IntPtr pClient);
- /* 获取协议版本 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpClient_GetVersion(IntPtr pClient);
- /* 获取内容长度 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern long HP_HttpClient_GetContentLength(IntPtr pClient);
- /* 获取内容类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpClient_GetContentType(IntPtr pClient);
- /* 获取内容编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpClient_GetContentEncoding(IntPtr pClient);
- /* 获取传输编码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_HttpClient_GetTransferEncoding(IntPtr pClient);
- /* 获取协议升级类型 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern HttpUpgradeType HP_HttpClient_GetUpgradeType(IntPtr pClient);
- /* 获取解析错误代码 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_HttpClient_GetParseErrorCode(IntPtr pClient, ref IntPtr lpszErrorDesc);
- /* 获取某个请求头(单值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetHeader(IntPtr pClient, string lpszName, ref IntPtr lpszValue);
- /* 获取某个请求头(多值) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetHeaders(IntPtr pClient, string lpszName, IntPtr[] lpszValue, ref uint pdwCount);
- /* 获取所有请求头 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetAllHeaders(IntPtr pClient, IntPtr lpHeaders, ref uint pdwCount);
- /* 获取所有请求头名称 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetAllHeaderNames(IntPtr pClient, IntPtr[] lpszName, ref uint pdwCount);
- /* 设置是否使用 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpClient_SetUseCookie(IntPtr pClient, bool bUseCookie);
- /* 检查是否使用 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_IsUseCookie(IntPtr pClient);
- /* 获取 Cookie */
- /* 获取 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetCookie(IntPtr pClient, string lpszName, ref IntPtr lpszValue);
- /* 获取所有 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetAllCookies(IntPtr pClient, IntPtr lpCookies, ref uint pdwCount);
- /* 获取当前 WebSocket 消息状态,传入 nullptr 则不获取相应字段 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_GetWSMessageState(IntPtr pClient, ref bool lpbFinal, ref byte lpiReserved, ref byte lpiOperationCode, ref IntPtr lpszMask, ref ulong lpullBodyLen, ref ulong lpullBodyRemain);
- /* 设置 HTTP 启动方式(默认:TRUE,自动启动) */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpClient_SetHttpAutoStart(IntPtr pClient, bool bAutoStart);
- /* 获取 HTTP 启动方式 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpClient_IsHttpAutoStart(IntPtr pClient);
- /**************************************************************************/
- /************************ HTTP Sync Client 操作方法 ************************/
- /// <summary>
- /// 名称:发送 URL 请求
- /// 描述:向服务端发送 HTTP URL 请求
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="lpszMethod">请求方法</param>
- /// <param name="lpszUrl">请求 URL</param>
- /// <param name="lpHeaders">请求头</param>
- /// <param name="iHeaderCount">请求头数量</param>
- /// <param name="pBody">请求体</param>
- /// <param name="iLength">请求体长度</param>
- /// <param name="bForceReconnect">强制重新连接(默认:FALSE,当请求 URL 的主机和端口与现有连接一致时,重用现有连接)</param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpSyncClient_OpenUrl(IntPtr pClient, string lpszMethod, string lpszUrl, THeader[] lpHeaders, int iHeaderCount, string pData, int iLength, bool bForceReconnect);
- /// <summary>
- /// 名称:清除请求结果
- /// 描述:清除上一次请求的响应头和响应体等结果信息(该方法会在每次发送请求前自动调用)
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpSyncClient_CleanupRequestResult(IntPtr pClient);
- /******************************************************************************/
- /************************ HTTP Sync Client 属性访问方法 ************************/
- /// <summary>
- /// 设置连接超时(毫秒,0:系统默认超时,默认:5000)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwConnectTimeout"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpSyncClient_SetConnectTimeout(IntPtr pClient, uint dwConnectTimeout);
- /// <summary>
- /// 设置请求超时(毫秒,0:无限等待,默认:10000)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwConnectTimeout"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpSyncClient_SetRequestTimeout(IntPtr pClient, uint dwRequestTimeout);
- /// <summary>
- /// 获取连接超时
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwConnectTimeout"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_HttpSyncClient_GetConnectTimeout(IntPtr pClient);
- /// <summary>
- /// 获取请求超时
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwConnectTimeout"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_HttpSyncClient_GetRequestTimeout(IntPtr pClient);
- /// <summary>
- /// 获取响应体
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwConnectTimeout"></param>
- /// <returns></returns>
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_HttpSyncClient_GetResponseBody(IntPtr pClient, ref IntPtr lpszBody, ref int iLength);
- /**************************************************************************/
- /*************************** HTTP Cookie 管理方法 **************************/
- /* 从文件加载 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_LoadFromFile(string lpszFile, bool bKeepExists /*= TRUE*/);
- /* 保存 Cookie 到文件 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_SaveToFile(string lpszFile, bool bKeepExists /*= TRUE*/);
- /* 清理 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_ClearCookies(string lpszDomain /*= nullptr*/, string lpszPath /*= nullptr*/);
- /* 清理过期 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_RemoveExpiredCookies(string lpszDomain /*= nullptr*/, string lpszPath /*= nullptr*/);
- /* 设置 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_SetCookie(string lpszName, string lpszValue, string lpszDomain, string lpszPath, int iMaxAge /*= -1*/, bool bHttpOnly /*= FALSE*/, bool bSecure /*= FALSE*/, int enSameSite /*= 0*/, bool bOnlyUpdateValueIfExists /*= TRUE*/);
- /* 删除 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_DeleteCookie(string lpszDomain, string lpszPath, string lpszName);
- /* 设置是否允许第三方 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_HttpCookie_MGR_SetEnableThirdPartyCookie(bool bEnableThirdPartyCookie /*= TRUE*/);
- /* 检查是否允许第三方 Cookie */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_MGR_IsEnableThirdPartyCookie();
- /* Cookie expires 字符串转换为整数 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_HLP_ParseExpires(string lpszExpires, ref ulong ptmExpires);
- /* 整数转换为 Cookie expires 字符串 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_HLP_MakeExpiresStr([MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszBuff, ref int piBuffLen, ulong tmExpires);
- /* 生成 Cookie 字符串 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_HttpCookie_HLP_ToString([MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszBuff, ref int piBuffLen, string lpszName, string lpszValue, string lpszDomain, string lpszPath, int iMaxAge /*= -1*/, bool bHttpOnly /*= FALSE*/, bool bSecure /*= FALSE*/, int enSameSite /*= 0*/);
- /* 获取当前 UTC 时间 */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ulong HP_HttpCookie_HLP_CurrentUTCTime();
- /* Max-Age -> expires */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ulong HP_HttpCookie_HLP_MaxAgeToExpires(int iMaxAge);
- /* expires -> Max-Age */
- [DllImport(Sdk.HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int HP_HttpCookie_HLP_ExpiresToMaxAge(ulong tmExpires);
- }
- }
|