Exemplo n.º 1
0
        public static void AsyncWebRequest(string url, ISendAsyncErrorHandler sendAsyncErrorHandler, AsyncCallback asyncCallback, Dictionary <string, string> headers = null)
        {
            // Get the URI from the command line.
            Uri httpSite = new Uri(url);

            // Create the request object.
            WebRequest wreq = WebRequest.Create(httpSite);

            if (headers != null)
            {
                foreach (string key in headers.Keys)
                {
                    wreq.Headers.Add(key, headers[key]);
                }
            }

            wreq.Timeout = 60 * 60 * 1000;
            // Create the state object.
            RequestState rs = new RequestState();

            // Put the request into the state object so it can be passed around.
            rs.Request = wreq;
            rs.SendAsyncErrorHandler = sendAsyncErrorHandler;

            // Issue the async request.
            IAsyncResult r = (IAsyncResult)wreq.BeginGetResponse(
                asyncCallback, rs);

            // Wait until the ManualResetEvent is set so that the application
            // does not exit until after the callback is called.
            //allDone.WaitOne();
        }
Exemplo n.º 2
0
 public ErrorEventArgs(string message, ISendAsyncErrorHandler sendAsyncErrorHandler)
     : base()
 {
     Message = message;
     SendAsyncErrorHandler = sendAsyncErrorHandler;
 }
Exemplo n.º 3
0
 public static void AsynWebRequest(string url, ISendAsyncErrorHandler sendAsyncErrorHandler)
 {
     AsyncWebRequest(url, sendAsyncErrorHandler, new AsyncCallback(RespCallback));
 }
Exemplo n.º 4
0
        public static void AsyncPostWebRequest(string url, string postData, Dictionary <string, string> headers, ISendAsyncErrorHandler sendAsyncErrorHandler, AsyncCallback asyncCallback)
        {
            // Get the URI from the command line.
            Uri httpSite = new Uri(url);

            // Create the request object.
            WebRequest wreq = WebRequest.Create(httpSite);

            StreamWriter requestWriter;

            if (wreq != null)
            {
                wreq.Method = "POST";
                //wreq.ServicePoint.Expect100Continue = false;
                wreq.Timeout = 60 * 60 * 1000;
                foreach (string key in headers.Keys)
                {
                    wreq.Headers.Add(key, headers[key]);
                }

                wreq.ContentType = "application/json";
                //POST the data.
                using (requestWriter = new StreamWriter(wreq.GetRequestStream()))
                {
                    requestWriter.Write(postData);
                }
            }

            wreq.Timeout = 60 * 60 * 1000;
            // Create the state object.
            RequestState rs = new RequestState();

            // Put the request into the state object so it can be passed around.
            rs.Request = wreq;
            rs.SendAsyncErrorHandler = sendAsyncErrorHandler;

            // Issue the async request.
            IAsyncResult r = (IAsyncResult)wreq.BeginGetResponse(
                asyncCallback, rs);

            // Wait until the ManualResetEvent is set so that the application
            // does not exit until after the callback is called.
            //allDone.WaitOne();
        }