Search code examples
c#httpwebrequest

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?


Solution

  • This should work:

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