| | |
| | | //public static Button LogoButton = new Button (); |
| | | |
| | | |
| | | public static string RequestVersion = "20200426"; |
| | | public static string RequestVersion = "2.506101"; |
| | | public static UserInfo LoginUser; |
| | | /// <summary> |
| | | /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token) |
| | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 请求服务器方法 |
| | | /// </summary> |
| | | /// <returns>The https.</returns> |
| | | /// <param name="methodType">请求方法.</param> |
| | | public static ResponsePack RequestHttpsNewBig (string methodType, byte [] byteData, UploadHomeAppGatewaySubFilesBigObj mUploadHomeAppGatewaySubFilesBigObj, string urlHead = "", int mTimeout = 10, string requestMethod = "POST") |
| | | { |
| | | ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => { |
| | | return true; |
| | | }; |
| | | |
| | | |
| | | #region HttpWebRequest |
| | | |
| | | try { |
| | | |
| | | if (urlHead == "") { |
| | | urlHead = RequestHttpsHost; |
| | | } |
| | | string requestFullUrl = urlHead + methodType; |
| | | |
| | | //初始化新的webRequst |
| | | //1. 创建httpWebRequest对象 |
| | | HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create (new Uri (requestFullUrl)); |
| | | |
| | | //2. 初始化HttpWebRequest对象 |
| | | webRequest.Method = requestMethod; |
| | | |
| | | //webRequest.Timeout = mTimeout * 1000; |
| | | |
| | | webRequest.Headers.Add (HttpRequestHeader.Authorization, LoginUser.LoginTokenString); |
| | | webRequest.Headers.Add ("RequestVersion", mUploadHomeAppGatewaySubFilesBigObj.RequestVersion); |
| | | webRequest.Headers.Add ("LoginAccessToken", LoginUser.LoginTokenString); |
| | | webRequest.Headers.Add ("HomeId", mUploadHomeAppGatewaySubFilesBigObj.HomeId); |
| | | webRequest.Headers.Add ("BackupClassId", mUploadHomeAppGatewaySubFilesBigObj.BackupClassId); |
| | | webRequest.Headers.Add ("FileName", mUploadHomeAppGatewaySubFilesBigObj.FileName); |
| | | webRequest.Headers.Add ("IsOtherAccountCtrl", mUploadHomeAppGatewaySubFilesBigObj.IsOtherAccountCtrl.ToString ()); |
| | | |
| | | |
| | | //var byteData = new byte [] { };//Encoding.UTF8.GetBytes (dataStringJson); |
| | | |
| | | //if (LoginUser != null) {/* 如果不需要验证Token可以不用传入 */ |
| | | // //对应微信网址 |
| | | |
| | | //} |
| | | |
| | | if (requestMethod == "GET") { |
| | | //webRequest.ContentType = "text/html"; |
| | | webRequest.ContentType = "application/json"; |
| | | } else { |
| | | webRequest.ContentType = "application/octet-stream"; |
| | | //webRequest.ContentType = "application/json"; |
| | | webRequest.ContentLength = byteData.Length; |
| | | |
| | | //3. 附加要POST给服务器的数据到HttpWebRequest对象(附加POST数据的过程比较特殊,它并没有提供一个属性给用户存取,需要写入HttpWebRequest对象提供的一个stream里面。) |
| | | var newStream = webRequest.GetRequestStream ();//创建一个Stream,赋值是写入HttpWebRequest对象提供的一个stream里面 |
| | | newStream.Write (byteData, 0, byteData.Length); |
| | | newStream.Flush (); |
| | | newStream.Close (); |
| | | } |
| | | |
| | | //4. 读取服务器的返回信息 |
| | | var response = (HttpWebResponse)webRequest.GetResponse (); |
| | | using (var stream = response.GetResponseStream ()) { |
| | | if (stream == null) { |
| | | return new ResponsePack () { StateCode = ErrorCode.NetworkError }; |
| | | } |
| | | var ms = new MemoryStream (); |
| | | var bytes = new byte [1024]; |
| | | var len = int.MaxValue; |
| | | while (stream.CanRead && 0 < len) { |
| | | len = stream.Read (bytes, 0, bytes.Length); |
| | | ms.Write (bytes, 0, len); |
| | | } |
| | | //var backBytes = ms.ToArray (); |
| | | string responseString = Encoding.UTF8.GetString (ms.ToArray ()); |
| | | |
| | | try { |
| | | ResponsePack revertObj = new ResponsePack () { }; |
| | | revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString); |
| | | if (revertObj.StateCode == null) { |
| | | revertObj.StateCode = "Data Exception"; |
| | | } |
| | | return revertObj; |
| | | } catch (Exception ex) { |
| | | Shared.Utlis.WriteLine (ex.ToString ()); |
| | | return new ResponsePack () { StateCode = "Data Exception" }; |
| | | } |
| | | |
| | | //return ms.ToArray (); |
| | | } |
| | | } catch (Exception ex) { |
| | | #if DEBUG |
| | | System.Console.WriteLine (ex.Message); |
| | | #endif |
| | | //The operation has timed out |
| | | return new ResponsePack () { StateCode = ErrorCode.NetworkError }; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | |
| | | |
| | | #region LoadingTipMsg 远程连接Tip |
| | | |
| | | static Button btnLoadingTipMsg; |
| | | |
| | | public static void LoadingTipShow (string tip) |
| | | { |
| | | |
| | | if (MainFrameLayout == null) { |
| | | return; |
| | | } |
| | | |
| | | Application.RunOnMainThread (() => { |
| | | try { |
| | | if (btnLoadingTipMsg == null) { |
| | | btnLoadingTipMsg = new Button () { |
| | | Height = Application.GetRealHeight (90), |
| | | BackgroundColor = SkinStyle.Current.MainColor, |
| | | //BackgroundColor = 0xFF000000, |
| | | Y = Application.GetRealHeight (36), |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = 0xFF000000, |
| | | }; |
| | | } |
| | | if (btnLoadingTipMsg.Parent == null) { |
| | | MainFrameLayout.AddChidren (btnLoadingTipMsg); |
| | | if (btnLoadingTipMsg.MouseUpEventHandler == null) { |
| | | btnLoadingTipMsg.MouseUpEventHandler += (sender, e) => { |
| | | if (btnLoadingTipMsg.Parent != null) |
| | | btnLoadingTipMsg.RemoveFromParent (); |
| | | }; |
| | | } |
| | | } |
| | | |
| | | btnLoadingTipMsg.Text = tip; |
| | | |
| | | } catch { } |
| | | }); |
| | | } |
| | | |
| | | public static void LoadingTipHide () |
| | | { |
| | | if (MainFrameLayout == null) { |
| | | return; |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | try { |
| | | if (btnLoadingTipMsg != null) { |
| | | if (btnLoadingTipMsg.Parent != null) |
| | | btnLoadingTipMsg.RemoveFromParent (); |
| | | } |
| | | |
| | | } catch { } |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 连接服务器失败 |
| | | /// </summary> |
| | | public static void FailureToServer () |