예제 #1
0
 public ResponseData postSendCode(string uri, string post, int i)
 {
     ResponseData result2;
     if (i < this.servers.Length)
     {
         byte[] rv = System.Text.Encoding.UTF8.GetBytes(post);
         System.Uri target = new System.Uri(this.servers[i] + uri);
         System.Net.WebRequest req = System.Net.WebRequest.Create(target);
         req.Method = "POST";
         req.PreAuthenticate = true;
         req.Timeout = this.timeout;
         req.ContentType = "application/x-www-form-urlencoded";
         req.ContentLength = (long)rv.Length;
         System.IO.Stream os = req.GetRequestStream();
         os.Write(rv, 0, rv.Length);
         os.Close();
         try
         {
             System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)req.GetResponse();
             string a = "";
             if (response == null)
             {
                 i++;
                 result2 = this.postSendCode(uri, post, i);
                 return result2;
             }
             System.IO.Stream receiveStream = response.GetResponseStream();
             System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
             System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode);
             char[] read = new char[256];
             for (int count = readStream.Read(read, 0, 256); count > 0; count = readStream.Read(read, 0, 256))
             {
                 string str = new string(read, 0, count);
                 a += str;
             }
             if (a != "")
             {
                 ResponseData result = new ResponseData();
                 result.getFromJson(a);
                 result2 = result;
                 return result2;
             }
             response.Close();
             result2 = new ResponseData();
             return result2;
         }
         catch (System.Net.WebException)
         {
             i++;
             result2 = this.postSendCode(uri, post, i);
             return result2;
         }
     }
     result2 = new ResponseData();
     return result2;
 }
예제 #2
0
 public ResponseData getRequestRegions(string uri, int i)
 {
     ResponseData res = new ResponseData();
     ResponseData result;
     if (i < this.servers2.Length)
     {
         System.Uri target = new System.Uri(this.servers2[i] + uri);
         System.Net.WebRequest req = System.Net.WebRequest.Create(target);
         req.Timeout = this.timeout;
         req.Method = "GET";
         req.PreAuthenticate = true;
         req.ContentType = "application/x-www-form-urlencoded";
         try
         {
             System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)req.GetResponse();
             if (response != null)
             {
                 System.IO.Stream receiveStream = response.GetResponseStream();
                 System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                 System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode);
                 string a = "";
                 char[] read = new char[256];
                 for (int count = readStream.Read(read, 0, 256); count > 0; count = readStream.Read(read, 0, 256))
                 {
                     string str = new string(read, 0, count);
                     a += str;
                 }
                 response.Close();
                 readStream.Close();
                 res.setXml(a);
             }
             else
             {
                 this.getRequestRegions(uri, i++);
             }
         }
         catch (System.Net.WebException)
         {
             i++;
             result = this.getRequestRegions(uri, i);
             return result;
         }
         result = res;
     }
     else
     {
         result = res;
     }
     return result;
 }