/// <summary> /// 发送POST数据 /// </summary> /// <param name="message">消息</param> /// <returns>返回消息</returns> public int sendRequest(FCMessage message) { FCBinary bw = new FCBinary(); byte[] body = message.m_body; int bodyLength = message.m_bodyLength; int uncBodyLength = bodyLength; if (message.m_compressType == COMPRESSTYPE_GZIP) { using (MemoryStream cms = new MemoryStream()) { using (GZipStream gzip = new GZipStream(cms, CompressionMode.Compress)) { gzip.Write(body, 0, body.Length); } body = cms.ToArray(); bodyLength = body.Length; } } int len = sizeof(int) * 4 + bodyLength + sizeof(short) * 3 + sizeof(byte) * 2; bw.writeInt(len); bw.writeShort((short)message.m_groupID); bw.writeShort((short)message.m_serviceID); bw.writeShort((short)message.m_functionID); bw.writeInt(message.m_sessionID); bw.writeInt(message.m_requestID); bw.writeByte((byte)message.m_state); bw.writeByte((byte)message.m_compressType); bw.writeInt(uncBodyLength); bw.writeBytes(body); byte[] bytes = bw.getBytes(); int length = bytes.Length; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(m_url); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = bytes.Length; if (bytes != null) { Stream writer = webReq.GetRequestStream(); writer.Write(bytes, 0, bytes.Length); writer.Close(); } HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); Stream reader = response.GetResponseStream(); long contentLength = response.ContentLength; byte[] dataArray = new byte[contentLength]; for (int i = 0; i < contentLength; i++) { dataArray[i] = (byte)reader.ReadByte(); } response.Close(); reader.Dispose(); bw.close(); int ret = dataArray.Length; UpFlow += ret; FCClientService.callBack(message.m_socketID, 0, dataArray, ret); return(ret); }
/// <summary> /// 数据回调 /// </summary> /// <param name="socketID"></param> /// <param name="localSID"></param> /// <param name="str"></param> /// <param name="len"></param> public void callBack(int socketID, int localSID, byte[] str, int len) { FCClientService.callBack(socketID, localSID, str, len); }
/// <summary> /// 写日志 /// </summary> /// <param name="socketID"></param> /// <param name="localSID"></param> /// <param name="state"></param> /// <param name="log"></param> public void writeLog(int socketID, int localSID, int state, String log) { FCClientService.writeClientLog(socketID, localSID, state, log); }
/// <summary> /// 添加服务 /// </summary> /// <param name="service">服务</param> public static void addService(FCClientService service) { m_services.put(service.ServiceID, service); }