コード例 #1
0
ファイル: Helper.cs プロジェクト: 15831944/EPC
        public static void CallApi(EnumApi api, UploadDataCompletedEventHandler strHandler, object obj)
        {
            using (WebClient client = new WebClient())
            {
                #region 消息头
                client.Headers["Type"] = "Post";
                client.Headers.Add("Content-Type", ConfigurationManager.AppSettings["Content-Type"]);
                client.Encoding = Encoding.UTF8;
                #endregion

                #region PostData
                string postData = JsonConvert.SerializeObject(obj);
                byte[] bytes    = Encoding.UTF8.GetBytes(postData);
                client.Headers.Add("ContentLength", postData.Length.ToString());
                #endregion

                #region 回调处理
                client.UploadDataCompleted += strHandler;
                #endregion

                string uriString = GetConfigValue(api);
                if (!string.IsNullOrEmpty(uriString))
                {
                    client.UploadDataAsync(new Uri(GetConfigValue(api)), bytes);
                }
            }
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: 15831944/EPC
        public static string GetConfigValue(EnumApi apiEnum)
        {
            string result = "";

            switch (apiEnum)
            {
            case EnumApi.GetPublishDetail:
                result = ConfigurationManager.AppSettings["EPMApi_GetPublishDetail"];
                break;

            case EnumApi.UpdatePrintConfig:
                result = ConfigurationManager.AppSettings["EPMApi_UpdatePrintConfig"];
                break;

            case EnumApi.Print:
                result = ConfigurationManager.AppSettings["EPMApi_Print"];
                break;

            default:
                throw new Exception("GetApiUri无对应EnumApi处理分支");
            }

            return(result);
        }