Esempio n. 1
0
 public bool HttpGet(string url, ushort msgID, bool binary = false, byte[] customData = null)
 {
     try
     {
         ClientSession.HttpResponeState httpResponeState = new ClientSession.HttpResponeState();
         httpResponeState.httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
         httpResponeState.responseMsgID = msgID;
         httpResponeState.responseBinary = binary;
         httpResponeState.userData = customData;
         httpResponeState.httpWebRequest.ContentType = "application/x-www-form-urlencoded";
         httpResponeState.httpWebRequest.Method = "GET";
         httpResponeState.httpWebRequest.UserAgent = "ma32";
         IAsyncResult asyncResult = httpResponeState.httpWebRequest.BeginGetResponse(new AsyncCallback(this.GetResponseCallBack), httpResponeState);
         ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.TimeoutCallback), httpResponeState.httpWebRequest, 15000, true);
     }
     catch (WebException ex)
     {
         global::Debug.LogErrorFormat("HttpGet Exception raised! \nMessage:{0} \nStatus:{1} !", new object[]
         {
             ex.Message,
             ex.Status
         });
         bool result = false;
         return result;
     }
     catch (Exception ex2)
     {
         global::Debug.LogException("HttpGet Exception raised!", ex2);
         bool result = false;
         return result;
     }
     return true;
 }
Esempio n. 2
0
 private void GetRequestStreamCallBack(IAsyncResult ar)
 {
     ClientSession.HttpRequestState httpRequestState = (ClientSession.HttpRequestState)ar.AsyncState;
     ClientSession.HttpResponeState httpResponeState = new ClientSession.HttpResponeState();
     httpResponeState.httpWebRequest = httpRequestState.httpWebRequest;
     httpResponeState.responseMsgID = httpRequestState.responseMsgID;
     try
     {
         Stream stream = httpRequestState.httpWebRequest.EndGetRequestStream(ar);
         if (httpRequestState.stream != null)
         {
             stream.Write(httpRequestState.stream.ToArray(), 0, (int)httpRequestState.stream.Length);
         }
         stream.Close();
         IAsyncResult asyncResult = httpRequestState.httpWebRequest.BeginGetResponse(new AsyncCallback(this.GetResponseCallBack), httpResponeState);
         ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.TimeoutCallback), httpRequestState.httpWebRequest, 15000, true);
     }
     catch (Exception ex)
     {
         global::Debug.LogErrorFormat("GetRequestStreamCallBack Exception, msg = {0}", new object[]
         {
             ex.Message
         });
         MemoryStream memoryStream = new MemoryStream();
         BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
         binaryWriter.Write(0);
         binaryWriter.Write(httpRequestState.responseMsgID);
         binaryWriter.Write(503);
         object obj = this.obj;
         lock (obj)
         {
             memoryStream.Position = 0L;
             this.msgQueue[this.recvIndex].Enqueue(memoryStream);
         }
     }
 }