Esempio n. 1
0
        public static void HttpCallBack(IAsyncResult result)
        {
            try
            {
                HttpPostState state = (HttpPostState)result.AsyncState;

                using (HttpWebResponse httpResponse = (HttpWebResponse)state.Request.EndGetResponse(result))
                {
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        _color = Color.Green;
                    }
                    else
                    {
                        _color = Color.Black;
                    }
                    _message  = "Code:" + httpResponse.StatusCode.ToString();
                    _message += Environment.NewLine;
                    _message += "Description" + httpResponse.StatusDescription;
                }
            }
            catch (Exception ex)
            {
                _message = ex.Message;
                _color   = Color.Red;
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                button1.Enabled = false;
                if (string.IsNullOrEmpty(textBox2.Text))
                {
                    _message = "No EDI url specified";
                    _color   = Color.Red;
                    return;
                }

                if (string.IsNullOrEmpty(textBox1.Text))
                {
                    _message = "No File specified";
                    _color   = Color.Red;
                    return;
                }
                _message = "Start Post file";
                using (StreamReader f = new StreamReader(textBox1.Text))
                {
                    string      ediUrl   = textBox2.Text;
                    XmlDocument document = new XmlDocument();
                    document.LoadXml(f.ReadToEnd());

                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ediUrl);
                    request.Method = "POST";

                    byte[] byteData = UTF8Encoding.UTF8.GetBytes(document.OuterXml);
                    using (Stream s = request.GetRequestStream())
                    {
                        s.Write(byteData, 0, byteData.Length);
                    }

                    HttpPostState state = new HttpPostState(request);

                    IAsyncResult result = request.BeginGetResponse(HttpCallBack, state);
                    result.AsyncWaitHandle.WaitOne();
                }
            }
            catch (Exception ex)
            {
                _message = ex.Message;
                _color   = Color.Red;
            }
            finally
            {
                button1.Enabled = true;
                button1.Refresh();
            }
        }