Exemplo n.º 1
0
 /// <summary>
 /// 设置 WebAPI 调用参数
 /// </summary>
 /// <param name="url">WebAPI 地址</param>
 /// <param name="contentType">报文类型:JSON, XML</param>
 /// <param name="clientID">客户端标识</param>
 public void SetWebAPIParams(string url, string contentType, string clientID)
 {
     webAPIUrl = url;
     try { this.contentType = (TContentType)Enum.Parse(typeof(TContentType), contentType); }
     catch { this.contentType = TContentType.JSON; }
     this.clientID = clientID;
 }
Exemplo n.º 2
0
 public TGetOPCServerTagList(
     string webAPIUrl,
     TContentType contentType,
     string clientID) : base(webAPIUrl, contentType, clientID)
 {
     moduleType = TModuleType.Exchange;
     exCode     = "IRAP_MES_GetOPCServerTagList";
 }
Exemplo n.º 3
0
 public TGetInfoStationLogin(
     string webAPIUrl,
     TContentType contentType,
     string clientID) : base(webAPIUrl, contentType, clientID)
 {
     moduleType = TModuleType.Exchange;
     exCode     = "IRAP_Core_GetInfoStationLogin";
 }
Exemplo n.º 4
0
        private TCustomWebAPICall()
        {
            webAPIUrl = GetValueFromAppSettings("WebAPI Broker", "http://127.0.0.1:55552/");

            string temp = GetValueFromAppSettings("Content Type", "JSON");

            try { contentType = (TContentType)Enum.Parse(typeof(TContentType), temp); }
            catch { contentType = TContentType.JSON; }

            clientID = GetValueFromAppSettings("ClientID", "MESDeveloper");
        }
Exemplo n.º 5
0
        public static string PostFormData(string url, byte[] args = null, TContentType tcntype = TContentType.FormData, string charset = "utf-8")
        {
            Stream       stream       = null;
            WebResponse  wbResponse   = null;
            StreamReader streamReader = null;

            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.KeepAlive = false;
                request.Timeout   = 180000;// 3分钟
                request.ServicePoint.Expect100Continue = false;
                if (tcntype != TContentType.None)
                {
                    request.ContentType = $"{TCONTENTTYPE[tcntype]};charset={charset}";
                }
                request.Method = "POST";

                stream = request.GetRequestStream();
                if (args != null)
                {
                    stream.Write(args, 0, args.Length);
                }

                wbResponse   = request.GetResponse();
                stream       = wbResponse.GetResponseStream();
                streamReader = new StreamReader(stream);

                return(streamReader.ReadToEnd());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                try
                {
                    streamReader.Close();
                }
                catch { }
                try
                {
                    stream.Close();
                }
                catch { }
                try
                {
                    wbResponse.Close();
                }
                catch { }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cookies">key:domain,value:.5173abc=hhhhhhh</param>
        /// <param name="method"></param>
        /// <param name="tcntype"></param>
        /// <param name="charset"></param>
        /// <param name="args"></param>
        /// <param name="postString"></param>
        /// <returns></returns>
        public static string RequestWithCookies(string url, List <KeyValuePair <string, KeyValuePair <string, string> > > cookies, TMethod method = TMethod.GET, TContentType tcntype = TContentType.FormUrl, string charset = "utf-8", byte[] args = null, string postString = "")
        {
            Stream       stream       = null;
            WebResponse  wbResponse   = null;
            StreamReader streamReader = null;

            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.KeepAlive = false;
                request.Timeout   = 180000;// 3分钟
                request.ServicePoint.Expect100Continue = false;
                request.ContentType = $"{TCONTENTTYPE[tcntype]};charset={charset}";
                request.Method      = method.ToString();

                if (method == TMethod.POST)
                {
                    stream = request.GetRequestStream();

                    if (postString.IsNotNullOrEmpty())
                    {
                        args = Encoding.UTF8.GetBytes(postString);
                    }
                    if (args != null)
                    {
                        stream.Write(args, 0, args.Length);
                    }
                }
                if (cookies != null && cookies.Count > 0)
                {
                    CookieContainer cc = new CookieContainer();
                    //cc.MaxCookieSize = 65535;
                    foreach (KeyValuePair <string, KeyValuePair <string, string> > kvp in cookies)
                    {
                        var item = kvp.Key;
                        var vle  = kvp.Value.Value;
                        if (vle.Contains(","))
                        {
                            vle = System.Web.HttpUtility.UrlEncode(vle);
                        }
                        cc.Add(new Cookie()
                        {
                            CommentUri = new Uri(url),
                            Domain     = kvp.Key,
                            Name       = kvp.Value.Key,
                            Value      = vle
                        });
                    }
                    //request.CookieContainer.MaxCookieSize = 65535;
                    request.CookieContainer = cc;
                }

                wbResponse   = request.GetResponse();
                stream       = wbResponse.GetResponseStream();
                streamReader = new StreamReader(stream);

                return(streamReader.ReadToEnd());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                try
                {
                    streamReader.Close();
                }
                catch { }
                try
                {
                    stream.Close();
                }
                catch { }
                try
                {
                    wbResponse.Close();
                }
                catch { }
            }
        }
Exemplo n.º 7
0
 public TGetDeliveryOrdersOnRoad(
     string webAPIUrl,
     TContentType contentType,
     string clientID) : base(webAPIUrl, contentType, clientID)
 {
 }
Exemplo n.º 8
0
 public TCustomWebAPICall(string webAPIUrl, TContentType contentType, string clientID)
 {
     this.webAPIUrl   = webAPIUrl;
     this.contentType = contentType;
     this.clientID    = clientID;
 }