Esempio n. 1
0
        public static string HttpPost(string url, string body)
        {
            try
            {
                Encoding       encoding = Encoding.UTF8;
                HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(url);
                request.Method      = "POST";
                request.Accept      = "text/html,application/xhtml+xml,*/*";
                request.ContentType = "application/json";

                byte[] buffer = encoding.GetBytes(body);
                request.ContentLength = buffer.Length;
                request.GetRequestStream().Write(buffer, 0, buffer.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    return(reader.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                LogApp.OutputErrorLog("WebApiInfo", "HttpPost", ex);
                LogApp.OutputErrorLog("WebApiInfo", "HttpPost", url);
                return(string.Empty);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 共通変数が初期化
        /// </summary>
        public static void InitVariableInfo()
        {
            try
            {
                clientPath = Application.StartupPath;

                iniFile = clientPath + "\\" + Constants.INI_NAME;

                tempPath  = VariableInfo.GetFullFileName(clientPath, "Temp");
                filesPath = VariableInfo.GetFullFileName(clientPath, "Files");
                logsPath  = VariableInfo.GetFullFileName(clientPath, "Logs");

                if (Directory.Exists(tempPath) == false)
                {
                    Directory.CreateDirectory(tempPath);
                }
                if (Directory.Exists(filesPath) == false)
                {
                    Directory.CreateDirectory(filesPath);
                }

                if (Directory.Exists(logsPath) == false)
                {
                    Directory.CreateDirectory(logsPath);
                }
            }
            catch (Exception ex)
            {
                LogApp.OutputErrorLog("VariableInfo", "InitVariableInfo", ex);
            }
        }
Esempio n. 3
0
        public static string DownloadFile(string url, string id)
        {
            try
            {
                string file = VariableInfo.GetFullFileName(VariableInfo.FilesPath, Path.GetFileName(url));
                if (File.Exists(file) == false)
                {
                    WebClient client = new WebClient();
                    client.DownloadFile(url, file);
                }

                return(file);
            }
            catch (Exception ex)
            {
                LogApp.OutputErrorLog("WebApiInfo", "DownloadFile", ex);
                LogApp.OutputErrorLog("WebApiInfo", "DownloadFile", url);
                return(string.Empty);
            }
        }
Esempio n. 4
0
        public static string HttpGet(string url)
        {
            try
            {
                Encoding       encoding = Encoding.UTF8;
                HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(url);
                request.Method      = "GET";
                request.Accept      = "text/html,application/xhtml+xml,*/*";
                request.ContentType = "application/json";

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    return(reader.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                LogApp.OutputErrorLog("WebApiInfo", "HttpGet", ex);
                LogApp.OutputErrorLog("WebApiInfo", "HttpGet", url);
                return(string.Empty);
            }
        }