本文整理汇总了C#中System.Net.HttpWebRequest.BeginGetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.BeginGetResponse方法的具体用法?C# HttpWebRequest.BeginGetResponse怎么用?C# HttpWebRequest.BeginGetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpWebRequest
的用法示例。
在下文中一共展示了HttpWebRequest.BeginGetResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRequest
private void GetRequest(string word)
{
Uri reqUri = GetRequestUri(word);
request = (HttpWebRequest)WebRequest.Create(reqUri);
AsyncCallback callback = new AsyncCallback(ProcessRequest);
request.BeginGetResponse(callback, null);
}
示例2: Download
public void Download(String URL)
{
URL = HttpUtility.UrlEncode(URL);
string req_src = api_req_url + URL;
wr = (HttpWebRequest)HttpWebRequest.Create(new Uri(req_src, UriKind.Absolute));
wr.BeginGetResponse(new AsyncCallback(req_callback), wr);
}
示例3: GetResponseAsync
public Task<WebResponse> GetResponseAsync(HttpWebRequest request, int timeoutMs)
{
if (timeoutMs > 0)
{
return GetResponseAsync(request, TimeSpan.FromMilliseconds(timeoutMs));
}
var tcs = new TaskCompletionSource<WebResponse>();
try
{
request.BeginGetResponse(iar =>
{
try
{
var response = (HttpWebResponse)request.EndGetResponse(iar);
tcs.SetResult(response);
}
catch (Exception exc)
{
tcs.SetException(exc);
}
}, null);
}
catch (Exception exc)
{
tcs.SetException(exc);
}
return tcs.Task;
}
示例4: AsyncGetResponse
/// <summary>
/// Encapsulates GetResponse so tests don't invoke the request
/// </summary>
/// <param name="req">Request to Twitter</param>
/// <returns>Response to Twitter</returns>
public static HttpWebResponse AsyncGetResponse(HttpWebRequest req)
{
Exception asyncException = null;
var resetEvent = new ManualResetEvent(/*initialStateSignaled:*/ false);
HttpWebResponse res = null;
req.BeginGetResponse(
new AsyncCallback(
ar =>
{
try
{
res = req.EndGetResponse(ar) as HttpWebResponse;
}
catch (Exception ex)
{
asyncException = ex;
}
finally
{
resetEvent.Set();
}
}), null);
resetEvent.WaitOne();
if (asyncException != null)
{
throw asyncException;
}
return res;
}
示例5: BeginGetHeight
public void BeginGetHeight(XYPoint point, int UTMZone)
{
string url = String.Format("http://kmswww3.kms.dk/FindMinHoejde/Default.aspx?display=show&csIn=utm{2}_euref89&csOut=utm32_euref89&x={0}&y={1}&c=dk", point.X, point.Y, UTMZone);
request = (HttpWebRequest)WebRequest.Create(url);
result= (IAsyncResult) request.BeginGetResponse(new AsyncCallback(RespCallback),null);
}
示例6: GetResponseAsynch
private HttpWebResponse GetResponseAsynch(HttpWebRequest request)
{
return AsynchHelper.WaitForAsynchResponse(
c => request.BeginGetResponse(c, null),
(r, s) => (HttpWebResponse)request.EndGetResponse(r)
);
}
示例7: FetchSearchResults
public void FetchSearchResults(HttpWebRequest queryRequest)
{
this.WebResultCollection.Clear();
IsLoading = true;
queryRequest.BeginGetResponse(new AsyncCallback(ReadCallback), queryRequest);
}
示例8: button_Click
private void button_Click(object sender, RoutedEventArgs e)
{
if (list.Items.Count != 0)
list.Items.Clear();
http = (HttpWebRequest)WebRequest.Create("http://192.168.2.39/TOSWEB/webservice/service.php");
http.BeginGetResponse(new AsyncCallback(ReadWebRequestCallBack), http);
}
示例9: OnNavigatedTo
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
DownloadStatusText.Text = "Downloading image from " + imageUrl;
webRequest = (HttpWebRequest)HttpWebRequest.CreateHttp(imageUrl);
webRequest.BeginGetResponse(new AsyncCallback(ResponseCallback), webRequest);
base.OnNavigatedTo(e);
}
示例10: IssueRequest
public static IEnumerator<object> IssueRequest(HttpWebRequest request)
{
var fResponse = new Future<HttpWebResponse>();
ThreadPool.QueueUserWorkItem(
(__) => {
try {
request.BeginGetResponse(
(ar) => {
try {
var _ = (HttpWebResponse)request.EndGetResponse(ar);
fResponse.SetResult(_, null);
} catch (Exception ex) {
fResponse.SetResult(null, ex);
}
}, null
);
} catch (Exception ex_) {
fResponse.SetResult(null, ex_);
}
}
);
yield return fResponse;
if (fResponse.Failed)
throw new RequestFailedException(fResponse.Error);
using (var response = fResponse.Result) {
var fResponseStream = Future.RunInThread(
() => response.GetResponseStream()
);
yield return fResponseStream;
Encoding encoding = AsyncTextReader.DefaultEncoding;
if (!string.IsNullOrEmpty(response.CharacterSet))
encoding = Encoding.GetEncoding(response.CharacterSet);
string responseText;
using (var stream = fResponseStream.Result)
using (var adapter = new AsyncTextReader(new StreamDataAdapter(stream, false), encoding)) {
var fText = adapter.ReadToEnd();
yield return fText;
responseText = fText.Result;
}
var cookies = new Cookie[response.Cookies.Count];
response.Cookies.CopyTo(cookies, 0);
yield return new Result(new Response {
Body = responseText,
ContentType = response.ContentType,
StatusCode = response.StatusCode,
StatusDescription = response.StatusDescription,
Cookies = cookies
});
}
}
示例11: SendCommandAsync
public void SendCommandAsync(JsonAsyncCallback jCallback)
{
jb = jCallback;
//String qryString = uri + name + "?" + (secret != Guid.Empty ? ("secret=" + secret.ToString() + "&") : "") + paramString;
String qryString = uri + name + "?" + paramString;
request = (HttpWebRequest)HttpWebRequest.Create(qryString);
IAsyncResult result = (IAsyncResult)request.BeginGetResponse(RespCallback, null);
}
示例12: SendMinecraftNetBeat
static void SendMinecraftNetBeat() {
HeartbeatData data = new HeartbeatData( MinecraftNetUri );
if( !RaiseHeartbeatSendingEvent( data, MinecraftNetUri, true ) ) {
return;
}
minecraftNetRequest = CreateRequest( data.CreateUri() );
var state = new HeartbeatRequestState( minecraftNetRequest, data );
minecraftNetRequest.BeginGetResponse( ResponseCallback, state );
}
示例13: GetData
public void GetData()
{
using (var File = IsolatedStorageFile.GetUserStoreForApplication())
{
request = (HttpWebRequest)HttpWebRequest.Create("http://www.search4rss.com/search.php?lang=en&q=" + txt_Search.Text);
Dispatcher.BeginInvoke(() => RssList.Visibility=Visibility.Collapsed);
Dispatcher.BeginInvoke(() => Loading_for_Search.Visibility=Visibility.Visible);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
}
示例14: DownloadDataAsync
public void DownloadDataAsync(HttpWebRequest request, byte[] d, int millisecondsTimeout,
RequestCompletedEventHandler completedCallback)
{
RequestState state = new RequestState(request, d, millisecondsTimeout, completedCallback, null);
IAsyncResult result = request.BeginGetResponse(GetResponse, state);
#if !NETFX_CORE
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, state, millisecondsTimeout, true);
#endif
}
示例15: GetAsync
/// <summary>Attempts to get data from a web request.</summary>
/// <param name="request">The HTTP web request.</param>
/// <param name="method">The OneAll supported HTTP method to use.</param>
/// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
/// <param name="callBack">The call-back to invoke after the request is complete.</param>
/// <param name="state">The initial state object provided.</param>
private static void GetAsync(HttpWebRequest request, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
{
request.SetHTTPMethod(method);
request.SetBasicAuth(creds);
request.BeginGetResponse(OnRequestCompleted, new BinaryWebClientState()
{
Request = request,
Callback = callBack,
State = state
});
}