Пример #1
0
        internal string JsonSendToServer(string jsonString, int type)
        {
            HttpWebRequest  httpWebRequest  = null;
            HttpWebResponse httpWebResponse = null;

            string webAddr;

            if (type == 1)
            {
                webAddr = UserInfo.serverUrl + "firstLoginCheckFileList";
            }
            else if (type == 2)
            {
                webAddr = UserInfo.serverUrl + "downloadList";
            }
            else if (type == 4)
            {
                webAddr = UserInfo.serverUrl + "uploadCheck";
            }
            else if (type == 5)
            {
                webAddr = UserInfo.serverUrl + "fileChangeCheck";
            }
            else if (type == 6)
            {
                webAddr = UserInfo.serverUrl + "eachDownload";
            }
            else
            {
                webAddr = UserInfo.serverUrl + "resultResponeReturnDateTime";
            }

            try
            {
                Uri uri = new Uri(webAddr);

                httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);

                if (type == 1 || type == 3 || type == 4 || type == 5)
                {
                    httpWebRequest.ContentType = "application/json; charset=utf-8";
                }
                else if (type == 2)
                {
                    httpWebRequest.ContentType = "application/octet-stream";
                }

                httpWebRequest.Timeout = 30000;
                httpWebRequest.Method  = "POST";

                // 인코딩1 - UTF-8
                byte[] data = Encoding.UTF8.GetBytes(jsonString);
                httpWebRequest.ContentLength = data.Length;


                // 데이터 전송
                Stream dataStream = httpWebRequest.GetRequestStream();
                dataStream.Write(data, 0, data.Length);
                dataStream.Close();

                // 전송응답
                if (type == 1 || type == 3 || type == 4 || type == 5)
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    Stream       responseStream = httpWebResponse.GetResponseStream();
                    StreamReader streamReader   = new StreamReader(responseStream, Encoding.UTF8);
                    result = streamReader.ReadToEnd();

                    // 연결닫기
                    streamReader.Close();
                    responseStream.Close();
                    httpWebResponse.Close();
                }
                else if (type == 2)
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    Stream       responseStream = httpWebResponse.GetResponseStream();
                    StreamReader streamReader   = new StreamReader(responseStream, Encoding.UTF8);

                    currentPath = Directory.GetCurrentDirectory();
                    currentPath = currentPath.Replace(@"\", @"/") + "/";

                    Debug.WriteLine("GetCurrentDirectory : " + currentPath);

                    FileStream   fileStream  = new FileStream(currentPath + test + ".zip", FileMode.Create);
                    BinaryWriter writeBinary = new BinaryWriter(fileStream);
                    BinaryReader readBinary  = new BinaryReader(streamReader.BaseStream);
                    byte[]       zipByte     = readBinary.ReadBytes((int)httpWebResponse.ContentLength);
                    writeBinary.Write(zipByte);

                    zipPath = currentPath + test + ".zip";
                    result  = "created zip file";

                    // 연결닫기
                    fileStream.Close();
                    streamReader.Close();
                    responseStream.Close();
                    httpWebResponse.Close();
                }
                else if (type == 6)
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    Stream       responseStream = httpWebResponse.GetResponseStream();
                    StreamReader streamReader   = new StreamReader(responseStream, Encoding.UTF8);

                    FileStream   fileStream  = new FileStream(Chat_Form.cloudDirPath + fileName, FileMode.Create);
                    BinaryWriter writeBinary = new BinaryWriter(fileStream);
                    BinaryReader readBinary  = new BinaryReader(streamReader.BaseStream);
                    byte[]       zipByte     = readBinary.ReadBytes((int)httpWebResponse.ContentLength);
                    Key.BCapsulation(UserInfo.Key, zipByte);
                    writeBinary.Write(zipByte);

                    result = "created file";

                    // 연결닫기
                    fileStream.Close();
                    streamReader.Close();
                    responseStream.Close();
                    httpWebResponse.Close();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("JsonSend Error : " + ex);
                return(result);
            }
            return(result);
        }