当前位置: 首页>>代码示例>>C#>>正文


C# WebRequest.BeginGetResponse方法代码示例

本文整理汇总了C#中System.Net.WebRequest.BeginGetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.BeginGetResponse方法的具体用法?C# WebRequest.BeginGetResponse怎么用?C# WebRequest.BeginGetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebRequest的用法示例。


在下文中一共展示了WebRequest.BeginGetResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

        public void Check(string currentVersion, Action<bool, Update[]> callback)
        {
            responseCallback = callback;
            webRequest = WebRequest.Create(string.Format(UpdateUrl, currentVersion));

            webRequest.BeginGetResponse(new AsyncCallback(finishRequest), null);
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:7,代码来源:Updater.cs

示例2: BeginProcessRequest

        public void BeginProcessRequest(Site site)
        {
            string sql = "";
            int iResult = 0;
            this.Site = site;

            oDataIO = new DataIO();
            SqlConnection Conn = new SqlConnection();
            Conn = oDataIO.GetDBConnection("ProfilesDB");
            sqlCmd = new SqlCommand();
            sqlCmd.Connection = Conn;

            site.IsDone = false;
            _request = WebRequest.Create(site.URL);

            // Enter log record
            sql = "insert into [Direct.].LogOutgoing(FSID,SiteID,Details,SentDate,QueryString) "
                 + " values ('" + site.FSID.ToString() + "'," + site.SiteID.ToString() + ",0,GetDate()," + cs(site.SearchPhrase) + ")";
            sqlCmd.CommandText = sql;
            sqlCmd.CommandType = System.Data.CommandType.Text;
            iResult = sqlCmd.ExecuteNonQuery();

            if (sqlCmd.Connection.State == System.Data.ConnectionState.Open)
                sqlCmd.Connection.Close();

            _request.BeginGetResponse(new AsyncCallback(EndProcessRequest), site);
        }
开发者ID:CTSIatUCSF,项目名称:ProfilesRNS10x-OpenSocial,代码行数:27,代码来源:DirectService.aspx.cs

示例3: BeginAsyncOperation

 IAsyncResult BeginAsyncOperation(object sender, EventArgs e,
     AsyncCallback cb, object state)
 {
     Trace.Write("BeginAsyncOperation");
     _request = WebRequest.Create("http://msdn.microsoft.com");
     return _request.BeginGetResponse(cb, state);
 }
开发者ID:jhpaterson,项目名称:PageAsyncTaskDemo,代码行数:7,代码来源:AsyncPage.aspx.cs

示例4: ImageBrowser

        public ImageBrowser()
        {
            InitializeComponent();

            //Get list of stock photos
            Uri uri = new Uri("http://docs.xamarin.com/demo/stock.json");
            request = WebRequest.Create(uri);
            request.BeginGetResponse(WebRequestCallback, null);
        }
开发者ID:tambama,项目名称:XamarinPreviewBook,代码行数:9,代码来源:ImageBrowser.xaml.cs

示例5: StartWebRequest

 private async Task StartWebRequest()
 {
     requester = (HttpWebRequest)WebRequest.Create(url);
     requester.BeginGetResponse(new AsyncCallback(FinishWebRequest), null);
     GettingData(BEGINDOWNLOAD);
     while (!go)
         await Task.Delay(500);
     GettingData(ENDDOWNLOAD);
 }
开发者ID:klausner17,项目名称:LeagueInfo,代码行数:9,代码来源:Requester.cs

示例6: BeginRequest

 private void BeginRequest(WebRequest request, AsyncCallback callback, object state)
 {
     var result = request.BeginGetResponse(callback, state);
     ClientEngine.MainLoop.QueueTimeout(RequestTimeout, delegate
     {
         if (!result.IsCompleted)
             request.Abort();
         return false;
     });
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:10,代码来源:HTTPTracker.cs

示例7: Get

 public void Get(WebRequest request, Action<HttpStatusCode, Stream> onComplete, Action<Uri, Exception> onError)
 {
     SetStandardHeaders(request);
     request.BeginGetResponse(HandleResponseCallback,
                              new RequestContext
                                  {
                                      Request = request,
                                      OnComplete = (code, s, entity) => onComplete(code, entity),
                                      OnError = onError,
                                  });
 }
开发者ID:warpzone81,项目名称:AccountRight_Live_API_.Net_SDK,代码行数:11,代码来源:ApiStreamRequestHandler.cs

示例8: DoWithResponse

 private static void DoWithResponse(WebRequest request, Action<HttpWebResponse> responseAction)
 {
     Action wrapperAction = () =>
     {
         request.BeginGetResponse(iar =>
         {
             var response = (HttpWebResponse)((HttpWebRequest)iar.AsyncState).EndGetResponse(iar);
             responseAction(response);
         }, request);
     };
     wrapperAction.BeginInvoke(iar =>
     {
         var action = (Action)iar.AsyncState;
         action.EndInvoke(iar);
     }, wrapperAction);
 }
开发者ID:mariogk,项目名称:Hu3,代码行数:16,代码来源:Program.cs

示例9: SearchForPlaceAync

        public void SearchForPlaceAync(GooglePlaceSearchRequest searchRequest)
        {
            var language = searchRequest.Language.HasValue ? Enum.GetName(typeof(GoogleMapsLanguage), searchRequest.Language.Value).Replace("_", "-") : null;
                var types = searchRequest.Types == null ? string.Empty : string.Join("|", searchRequest.Types);
                var requestUrl = string.Format(GooglePlacesAPI_Url, _appId, searchRequest.Sensor.ToString().ToLower(), searchRequest.Keyword);
                _webRequest = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
                _webRequest.Method = "Post";

                try
                {
                    _webRequest.BeginGetResponse(ResponseCallback, new List<object> { _webRequest, searchRequest });
                }
                catch (Exception e)
                {
                    SearchForPlacesAsyncFailed(e.Message, e);
                }
        }
开发者ID:travbod57,项目名称:DatingDiary,代码行数:17,代码来源:GooglePlacesTextSearchClient.cs

示例10: RequestAsync

        private static void RequestAsync(WebRequest request, byte[] bodyBytes, Action<TrackResult> callback)
        {
            request.BeginGetRequestStream((r1) =>
            {
                try
                {
                    var stream = request.EndGetRequestStream(r1);
                    stream.BeginWrite(bodyBytes, 0, bodyBytes.Length, (r2) =>
                    {
                        try
                        {
                            stream.EndWrite(r2);
                            stream.Dispose();

                            request.BeginGetResponse((r3) =>
                            {
                                try
                                {
                                    using (var response = request.EndGetResponse(r3))
                                    {
                                        using (var reader = new StreamReader(response.GetResponseStream()))
                                        {
                                            if (callback != null)
                                                callback(new TrackResult(reader.ReadToEnd()));
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    HandleError(callback, ex);
                                }
                            }, null);
                        }
                        catch (Exception ex)
                        {
                            HandleError(callback, ex);
                        }
                    }, null);
                }
                catch(Exception ex)
                {
                    HandleError(callback, ex);
                }
            }, null);
        }
开发者ID:gsdean,项目名称:Mixpanel.NET,代码行数:45,代码来源:MixpanelAsyncHttp.cs

示例11: GetResponseInternal

        private static WebResponse GetResponseInternal(WebRequest request)
        {            
            // build the envent
			using (var revent = new ManualResetEvent(false))
			{
				// start the async call
				IAsyncResult result = request.BeginGetResponse(new AsyncCallback(CallStreamCallback), revent);

				// wait for event
				revent.WaitOne();

				// get the response
				WebResponse response = request.EndGetResponse(result);

				// go ahead
				return response;
			}
        }
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:18,代码来源:WebRequestStreamHelper.cs

示例12: Execute

        public void Execute()
        {
            MobeelizerConfigurationSection section = (MobeelizerConfigurationSection)ConfigurationManager.GetSection("mobeelizer-configuration");
            String propUrl = null;

            String mode = null;
            try
            {
                propUrl = section.AppSettings[META_URL].Value;
            }
            catch (KeyNotFoundException) { }

            try
            {
                mode = section.AppSettings[META_MODE].Value;
            }
            catch (KeyNotFoundException) { }

            StringBuilder baseUrlBuilder = new StringBuilder();
            if (propUrl == null)
            {
                baseUrlBuilder.Append(Resources.Config.c_apiURL_host);
            }
            else
            {
                baseUrlBuilder.Append(propUrl);
            }

            baseUrlBuilder.Append(Resources.Config.c_apiURL_path);

            if ("test".Equals(mode.ToLower()))
            {
                baseUrlBuilder.Append("?test=true");
            }
            else
            {
                baseUrlBuilder.Append("?test=false");
            }
            baseUrlBuilder.Append("&disablecache=" + Guid.NewGuid());

            Uri url = new Uri(baseUrlBuilder.ToString());
            request = WebRequest.Create(url);
            request.BeginGetResponse(OnBeginGetResponse, null);
        }
开发者ID:mobeelizer,项目名称:wp7-api-demos,代码行数:44,代码来源:CreateSessionTask.cs

示例13: ExecuteGetOrDeleteAsync

        private WebQueryAsyncResult ExecuteGetOrDeleteAsync(ICache cache, 
                                                            string key, 
                                                            string url, 
                                                            WebRequest request,
                                                            object userState)
        {
            var fetch = cache.Get<Stream>(key);
            if (fetch != null)
            {
                var args = new WebQueryResponseEventArgs(fetch);
                OnQueryResponse(args);

                var result = new WebQueryAsyncResult
                {
                    CompletedSynchronously = true
                };
                return result;
            }
            else
            {
                var state = new Triplet<WebRequest, Pair<ICache, string>, object>
                                {
                                    First = request,
                                    Second = new Pair<ICache, string>
                                                 {
                                        First = cache,
                                        Second = key
                                    },
                                    Third = userState
                                };

                var args = new WebQueryRequestEventArgs(url);
                OnQueryRequest(args);

                var inner = request.BeginGetResponse(GetAsyncResponseCallback, state);
                RegisterAbortTimer(request, inner); 
                var result = new WebQueryAsyncResult { InnerResult = inner };
                return result;
            }
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:40,代码来源:WebQuery.Async.cs

示例14: Start

 private void Start()
 {
     try
     {
         request = System.Net.WebRequest.Create(requestURI);
         request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy();
         if (null != postData)
         {
             request.ContentLength = postData.Length;
             request.ContentType = "application/x-www-form-urlencoded";
             request.Method = "POST";
             request.BeginGetRequestStream(new AsyncCallback(GetRequestCallback), request);
         }
         else
         {
             request.Method = "GET";
             request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
         }
     }
     catch (OutOfMemoryException e)
     {
         if (retryCount < retryMax)
         {
             System.Diagnostics.Debug.WriteLine(e.Message);
             ++retryCount;
             Random random = new Random();
             Thread.Sleep(retryDelay * random.Next(retryCount * retryCount));
             Start();
         }
         else
         {
             OnException(e);
         }
     }
     catch (Exception e)
     {
         OnException(e);
     }
 }
开发者ID:MetricWise,项目名称:vtwsclib.NET,代码行数:39,代码来源:WebServiceAsyncRequest.cs

示例15: LoadAsync

        /// <summary>
        /// Loads this <see cref="RssFeed"/> instance asynchronously using the specified <see cref="Uri"/>, <see cref="SyndicationResourceLoadSettings"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="RssFeed"/> instance. This value can be <b>null</b>.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="userToken">A user-defined object that is passed to the method invoked when the asynchronous operation completes.</param>
        /// <remarks>
        ///     <para>
        ///         To receive notification when the operation has completed or the operation has been canceled, add an event handler to the <see cref="Loaded"/> event. 
        ///         You can cancel a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> operation by calling the <see cref="LoadAsyncCancel()"/> method.
        ///     </para>
        ///     <para>
        ///         After calling <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/>, 
        ///         you must wait for the load operation to complete before attempting to load the syndication resource using the <see cref="LoadAsync(Uri, Object)"/> method.
        ///     </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception>
        /// <exception cref="InvalidOperationException">This <see cref="RssFeed"/> has a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> call in progress.</exception>
        public void LoadAsync(Uri source, SyndicationResourceLoadSettings settings, WebRequestOptions options, Object userToken)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Use default settings if none specified by the caller
            //------------------------------------------------------------
            if (settings == null)
            {
                settings    = new SyndicationResourceLoadSettings();
            }

            //------------------------------------------------------------
            //	Validate syndication resource state
            //------------------------------------------------------------
            if (this.LoadOperationInProgress)
            {
                throw new InvalidOperationException();
            }

            //------------------------------------------------------------
            //	Indicate that a load operation is in progress
            //------------------------------------------------------------
            this.LoadOperationInProgress    = true;

            //------------------------------------------------------------
            //	Reset the asynchronous load operation cancelled indicator
            //------------------------------------------------------------
            this.AsyncLoadHasBeenCancelled  = false;

            //------------------------------------------------------------
            //	Build HTTP web request used to retrieve the syndication resource
            //------------------------------------------------------------
            asyncHttpWebRequest         = SyndicationEncodingUtility.CreateWebRequest(source, options);
            asyncHttpWebRequest.Timeout = Convert.ToInt32(settings.Timeout.TotalMilliseconds, System.Globalization.NumberFormatInfo.InvariantInfo);

            //------------------------------------------------------------
            //	Get the async response to the web request
            //------------------------------------------------------------
            object[] state      = new object[6] { asyncHttpWebRequest, this, source, settings, options, userToken };
            IAsyncResult result = asyncHttpWebRequest.BeginGetResponse(new AsyncCallback(AsyncLoadCallback), state);

            //------------------------------------------------------------
            //  Register the timeout callback
            //------------------------------------------------------------
            ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(AsyncTimeoutCallback), state, settings.Timeout, true);
        }
开发者ID:Jiyuu,项目名称:Argotic,代码行数:70,代码来源:GenericSyndicationFeed.cs


注:本文中的System.Net.WebRequest.BeginGetResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。