• webClient请求JAVA超时解决方案


        private class MyWebClient: WebClient {
                protected override WebRequest GetWebRequest(Uri uri) {
                    WebRequest w = base.GetWebRequest(uri);
                    w.Timeout = 20 * 60 * 1000;
                    return w;
                }
            }
            
    
    
            public static string  GetInnerModel(string str) {
                try {
    
            
    
                    string url = "http://xx.com/AgileWSPX/services/rest/transferModel/";
                    var rando = Random();
                    var postString = str;
                    var date = DateTime.Now.ToString("mmssffff");
                    byte[] postData = Encoding.UTF8.GetBytes(postString);
    
                    var code = Encrypt(date + rando,"dahuagdp");
    
                    MyWebClient client = new MyWebClient();
                    client.Headers.Add("Nonce","" + rando + "");
                    client.Headers.Add("Authorization","" + code + "");
                    client.Headers.Add("Content-Type","application/x-www-form-urlencoded;");
    
                    var httpurl = url + date;
                    byte[] responseData = client.UploadData(httpurl,"POST",postData);//得到返回字符流 
                    var data = Encoding.UTF8.GetString(responseData);
    
                    if(!string.IsNullOrEmpty(data)) {
    
                        var dataList = data.Split(',').Distinct();
                        data = string.Join(",",dataList.Select(p => p));
                    }
                    return data;
                } catch(Exception ex)
                {
                    return "";
                }
    
    
            }
            private static string Random() {
                return DateTime.Now.ToString("mmssffff");
            }
            public static string Encrypt(string pToDecrypt,string sKey) {
                try {
                    byte[] data = Encoding.UTF8.GetBytes(pToDecrypt);
                    using(var des = new DESCryptoServiceProvider()) {
                        des.Key = Encoding.UTF8.GetBytes(sKey);
                        des.IV = Encoding.UTF8.GetBytes(sKey);
                        using(MemoryStream ms = new MemoryStream()) {
                            using(var cs = new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write)) {
                                cs.Write(data,0,data.Length);
                                cs.FlushFinalBlock();
                            }
                            return Convert.ToBase64String(ms.ToArray());
                        }
                    }
                } catch {
                    return "";
                }
            }
  • 相关阅读:
    C字符串格式化
    oms登录bug
    宏旺文章审核功能使用指引
    phpcms文章审核
    html5的pushState 无刷新, 前进后退等
    js路由—backbone的路由的实现02
    js路由—backbone的路由的实现01
    js路由—简单路由的实现
    img标签和css的background-image的区别
    querySelector与querySelectorAll
  • 原文地址:https://www.cnblogs.com/flyfish2012/p/5649870.html
Copyright © 2020-2023  润新知