本文整理汇总了C#中WebRequest.BeginGetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.BeginGetResponse方法的具体用法?C# WebRequest.BeginGetResponse怎么用?C# WebRequest.BeginGetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebRequest
的用法示例。
在下文中一共展示了WebRequest.BeginGetResponse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 FSLogOutgoing(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);
}
示例2: DoWithResponse
void DoWithResponse(WebRequest request, Action<HttpWebResponse> responseAction)
{
Action wrapperAction = () =>
{
request.BeginGetResponse(new AsyncCallback((iar) =>
{
var response = (HttpWebResponse)((HttpWebRequest)iar.AsyncState).EndGetResponse(iar);
responseAction(response);
}), request);
};
wrapperAction.BeginInvoke(new AsyncCallback((iar) =>
{
var action = (Action)iar.AsyncState;
action.EndInvoke(iar);
}), wrapperAction);
}
示例3: BeginProcess
// 在此方法中开始你的异步操作
// 执行后立即返回
// HttpApplication 对象此时可以立即返回到池中
private IAsyncResult BeginProcess(object sender, EventArgs e, AsyncCallback cb, object extraData)
{
_request = HttpWebRequest.Create("http://www.sina.com.cn");
return _request.BeginGetResponse(cb, extraData);
}
示例4: runNetLoop
public void runNetLoop()
{
ManualResetEvent http_response_sync = new ManualResetEvent(false);
HttpWebResponse resp = null;
int registeredHandle = 0;
try
{
conn = HttpWebRequest.Create(url);//todomt (HttpConnection)Connector.open(url);
//System.Net.ServicePointManager.Expect100Continue = false;
if (method == 0) conn.Method = "GET";
else conn.Method = "POST";
if (updateTime != null && updateTime.Trim().Length > 0) {
conn.Headers["IfModifiedSince"] = updateTime;
}
registeredHandle = CRunTime.registerObject(conn);
}
catch (Exception e)
{
quit = true;
Logger.log(e.ToString());
UIWorker.addUIEventLog("Async Net : Exception opening URL " + e);
}
int handle = registeredHandle;
UIWorker.addUIEventValid(c_do_async_connect_cb, handle, cb_addr, context, 0, false, this);
if (quit) return;
while (!quit)
{
lock (conn)
{
if (!do_read)
{
try
{
Monitor.Wait(conn);
}
catch (SynchronizationLockException e)
{
}
if (quit) return;
if (!do_read) continue;
}
}
try
{
if (Stream == null)
{
resp = null;
Exception exp = null;
try
{
http_response_sync.Reset();
conn.BeginGetResponse(delegate(IAsyncResult result)
{
try
{
Logger.log("downloading " + conn.RequestUri);
resp = (HttpWebResponse)conn.EndGetResponse(result);
http_response_sync.Set();
}
catch (Exception we)
{
resp = null;
exp = we;
http_response_sync.Set();
}
}, null);
}
catch (Exception ioe)
{
resp = null;
exp = ioe;
http_response_sync.Set();
}
http_response_sync.WaitOne();
if (resp != null)
{
Stream = resp.GetResponseStream();
int status = (int)resp.StatusCode;
long data_size = resp.ContentLength;
string lastModifiedStr = resp.Headers["Last-Modified"];
//Logger.log("Java header, s is " + lastModifiedStr);
/*
* We need to send c a complete header string, so we fake it by creating the
* res string. More header fields can be added later on besides the content length and last-modified
*
*/
string res = "HTTP/1.1 " + status + " OK\r\nContent-Length: " + data_size + "\r\n";
if (lastModifiedStr != null)
//.........这里部分代码省略.........
示例5: GetResponse
/// <summary>
/// Equivalent of webRequest.GetResponse, but using our own RequestState.
/// This can or should be used along with web async instance's isResponseCompleted parameter
/// inside a IEnumerator method capable of yield return for it, although it's mostly for clarity.
/// Here's an usage example:
///
/// WebAsync webAsync = new WebAsync(); StartCoroutine( webAsync.GetReseponse(webRequest) );
/// while (! webAsync.isResponseCompleted) yield return null;
/// RequestState result = webAsync.requestState;
///
/// </summary>
/// <param name='webRequest'>
/// A System.Net.WebRequest instanced var.
/// </param>
public IEnumerator GetResponse (WebRequest webRequest) {
isResponseCompleted = false;
requestState = new RequestState();
// Put the request into the state object so it can be passed around
requestState.webRequest = webRequest;
// Do the actual async call here
IAsyncResult asyncResult = (IAsyncResult) webRequest.BeginGetResponse(
new AsyncCallback(RespCallback), requestState);
// WebRequest timeout won't work in async calls, so we need this instead
ThreadPool.RegisterWaitForSingleObject(
asyncResult.AsyncWaitHandle,
new WaitOrTimerCallback(ScanTimeoutCallback),
requestState,
(TIMEOUT *1000), // obviously because this is in miliseconds
true
);
// Wait until the the call is completed
while (!asyncResult.IsCompleted) { yield return null; }
// Help debugging possibly unpredictable results
if (requestState != null) {
if (requestState.errorMessage != null) {
// this is not an ERROR because there are at least 2 error messages that are expected: 404 and NameResolutionFailure - as can be seen on CheckForMissingURL
Debug.Log("[WebAsync] Error message while getting response from request '"+ webRequest.RequestUri.ToString() +"': "+ requestState.errorMessage);
}
}
isResponseCompleted = true;
}