Пример #1
0
 public void Download(Uri uri, object metaData, IParser parser)
 {
     uriParserPairs.Add(metaData, parser);
     var request = (HttpWebRequest)WebRequest.Create(uri);
     var state = new RequestState { Request = request, Metadata = metaData };
     request.BeginGetResponse(GetData, state);
 }
Пример #2
0
        public void Download(Uri targetUri, AsyncCallback callback)
        {
            var request = (HttpWebRequest)WebRequest.Create(targetUri);
            state = new RequestState { Request = request, stopTimer = false };

            request.BeginGetResponse(callback, state);

            timer = new Timer(x =>  {
                                        if (!state.stopTimer)
                                        {
                                            ((RequestState)x).Request.Abort();
                                        }
                                        timer.Dispose(); }, 
                                    state, 
                                    TimeSpan.FromSeconds(Settings.DefaultTimeOutSeconds), 
                                    TimeSpan.FromTicks(0));
        }
Пример #3
0
        public void DownloadPost(Uri targetUri, string key,  string data, AsyncCallback callback)
        {
            var request = (HttpWebRequest)WebRequest.Create(targetUri);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var state = new RequestState { Request = request };

            request.BeginGetRequestStream( ar =>
                                               {
                                                   var requestStream = request.EndGetRequestStream(ar);
                                                   using (var sw = new StreamWriter(requestStream))
                                                   {
                                                       sw.Write(String.Format("_method=POST&"));
                                                       sw.Write(String.Format("{0}={1}", key, data));
                                                   }

                                                   request.BeginGetResponse(callback, state);
                                               }, null);
        }