本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
});
}
示例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,
});
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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);
}