Inheritance: System.EventArgs
        public ResponseEventArgs Delete(string url, string userName, string password, string content)
        {
            ResponseEventArgs result = new ResponseEventArgs();
            HttpWebResponse webRes = null;
            //Stream requestStream = null;
            WebReq = (HttpWebRequest)WebRequest.Create(url);
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                //request.Credentials = new NetworkCredential(userName, password);
                string authInfo = userName + ":" + password;
                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(userName + ":" + password));
                WebReq.Headers["Authorization"] = "Basic " + authInfo;
            }
            WebReq.Method = "DELETE";
            WebReq.KeepAlive = true;
            WebReq.ContentType = content;

            //hasAuthenticationHeader();
            //addHeaders();
            try
            {
                webRes = (HttpWebResponse)WebReq.GetResponse();
                result._status = ((int)webRes.StatusCode).ToString();
                webRes.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (WebReq != null)
                {
                    WebReq = null;
                }

                if (webRes != null)
                {
                    webRes = null;
                }
            }
            return result;
        }
 public void OnGeoComResponseReceived(object geoComWebClient, ResponseEventArgs response)
 {
     if (GeoComResponseReceived != null)
     {
         GeoComResponseReceived(geoComWebClient, response);
     }
 }
        private void GetResponseBack(IAsyncResult asynchronousResult)
        {
            ResponseEventArgs args = new ResponseEventArgs();

            try
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

                args._status = response.StatusCode.ToString();

                if (response.Headers["Location"] != null)
                {
                    args._location = response.Headers["Location"].ToString();
                }

                response.Close();

                OnGeoComResponseReceived(this, args);
            }
            catch (Exception ex)
            {
                args._error = ex;
                OnGeoComResponseReceived(this, args);
            }
        }
        public ResponseEventArgs UploadFiles(string url, string[] files)
        {
            ResponseEventArgs result = new ResponseEventArgs();
            HttpWebResponse webRes = null;
            Stream requestStream = null;

            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

            WebReq = (HttpWebRequest)WebRequest.Create(url);

            WebReq.Method = "POST";
            WebReq.Timeout = System.Threading.Timeout.Infinite;
            WebReq.Accept = "*/*";
            WebReq.PreAuthenticate = true;
            WebReq.KeepAlive = true;
            WebReq.ContentType = "multipart/form-data; boundary=" + boundary;

            hasAuthenticationHeader();
            addHeaders();

            try
            {
                Stream memStream = getFilesMemoryStream(files, boundary);
                byte[] tempBuffer = getByteArray(memStream);
                memStream.Close();

                WebReq.ContentLength = tempBuffer.Length;

                requestStream = WebReq.GetRequestStream();
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
                requestStream.Close();

                webRes = (HttpWebResponse)WebReq.GetResponse();

                Stream response = webRes.GetResponseStream();
                try
                {
                    result._status = webRes.StatusCode.ToString();
                }
                catch { }
                try
                {
                    result._location = webRes.Headers["Location"].ToString();
                }
                catch { }

                response.Close();
                webRes.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (WebReq != null)
                {
                    WebReq = null;
                }

                if (webRes != null)
                {
                    webRes.Close();
                    WebReq = null;
                }
            }
            return result;
        }
        public ResponseEventArgs Put(string url, string data)
        {
            ResponseEventArgs result = new ResponseEventArgs();
            HttpWebResponse webRes = null;
            Stream requestStream = null;

            byte[] content = System.Text.Encoding.ASCII.GetBytes(data);

            WebReq = (HttpWebRequest)WebRequest.Create(url);
            WebReq.Method = "PUT";
            WebReq.KeepAlive = true;
            WebReq.ContentType = "text/plain";

            hasAuthenticationHeader();
            addHeaders();
            try
            {
                requestStream = WebReq.GetRequestStream();
                requestStream.Write(content, 0, content.Length);
                requestStream.Close();

                webRes = (HttpWebResponse)WebReq.GetResponse();

                var response = webRes.GetResponseStream();

                result._status = webRes.StatusCode.ToString();

                response.Close();
                webRes.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (requestStream != null)
                {
                    requestStream = null;
                }

                if (WebReq != null)
                {
                    WebReq = null;
                }

                if (webRes != null)
                {
                    webRes = null;
                }
            }

            return result;
        }
Exemple #6
0
 private void UploadFilesDataResponse(object webClient, ResponseEventArgs e)
 {
     ResponseStatusEventArgs args = new ResponseStatusEventArgs();
     if (e.Error == null)
     {
         args._result = e.Status;
         args._location = e.Location;
     }
     else
     {
         args._error = e.Error;
     }
     if (this.AsyncUploadFileComplete != null)
         AsyncUploadFileComplete(args);
 }