开发者

Getting Url in the call back function of WebRequesting

Let's say I have a web request:

WebRequest webRequest = WebRequest.Create(Url);
webRequest.BeginGetResponse(this.RespCallback, webRequest);

Now is there is any way to retrieve the URL in

private void RespCallback(IAsyncResult asynchronousResult)
{ 
    // here 
}
开发者_高级运维

The idea is I want to provide a sequence id in the url while doing web request and then retrieve it on the call back and match it to know that this call back is from that request.

Any ideas?


This should work:

private void RespCallback(IAsyncResult asynchronousResult)
{ 
    WebRequest wreq = asynchronousResult as WebRequest;
    Uri wreqUri = wreq.RequestUri;
}


Since you pass WebRequest as "state" to the BeginXXX cal you can retrive it in callback by accesing AsyncState property of IAsyncResult inside RespCallback. The get Url of your WebRequest.

var wr = asynchronousResult.AsyncState as WebRequest.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜