Exemple #1
0
 private void Net_Req(IAsyncResult res)
 {
     try
     {
         var req = res.AsyncState as HttpWebRequest;
         if (!isGet)
         {
             var bytes  = new System.Text.UTF8Encoding().GetBytes(toPost);
             var stream = req.EndGetRequestStream(res);
             stream.Write(bytes, 0, bytes.Length);
             stream.Flush();
         }
         req.BeginGetResponse(new AsyncCallback(Net_Resp), req);
     }
     catch (Exception e)
     {
         KirinAssistant.executeCallback(onError, "WebPost.Post_ReqStream() Just caught exception: " + e.GetType() + ", " + e.Message);
     }
 }
Exemple #2
0
        private void Net_Resp(IAsyncResult res)
        {
            try
            {
                var req  = (HttpWebRequest)res.AsyncState;
                var resp = (HttpWebResponse)req.EndGetResponse(res);

                var    streamReader = new StreamReader(resp.GetResponseStream());
                string s            = streamReader.ReadToEnd();
                KirinAssistant.executeCallback(payload, Uri.EscapeDataString(s));
            }
            catch (WebException e)
            {
                KirinAssistant.executeCallback(onError, "WebException: " + e.ToString());
            }
            catch (Exception e)
            {
                KirinAssistant.executeCallback(onError, "Exception: " + e.ToString());
            }
        }