0

I'd like to be able to modify the url contained in the RequestUri of a c# HttpWebRequest object. I'd like to append an additional parameter with a ticket Id. [like &ticket=xyz123]

It sounds like this may not be possible to do this because RequestUri is read only. Some people have suggested using reflection to get around it, but others say that even when you use reflection it won't work.

Is there some other way to get around this?

Would I be able to use the HttpWebRequest CookieContainer to include the ticket information -- although the ticket is not in a cookie, there is a special service call needed to retrieve the ticket string.

I'm trying to override an authentication method as follows:

    protected override void HttpAuthenticate(HttpWebRequest request)
    {
        Uri uri = request.RequestUri;
        Uri newUrl = new Uri(AuthData.appendTicket(uri.ToString()));
        request.RequestUri = newUrl;  // Cannot do this because it is readonly

1 Answer 1

1

With sufficient reflection hacking, you may be able to force it, but this goes against the basic architectural model of the class: the URL of a WebRequest is supposed to be fixed at creation-time. If you want to make a request to a different-but-related URL, why not use WebRequest.Create to create a new HttpWebRequest to a new URL formed by fiddling with the RequestUri of the original WebRequest?

Sign up to request clarification or add additional context in comments.

2 Comments

I'm just trying to override this one method to change the authentication mechanism. Standard Basic Authentication sets the credentials of the HttpWebRequest. Instead I'd like to be able to add the ticket information -- which is normally passed as an additional parameter on the URL.
I understand the desire, but it just doesn't work. You could change the parameter to be passed by ref, then change out the input HttpWebRequest for the new HttpWebRequest in the method. Probably the main reason HttpWebRequest is constructed this way is to prevent you swapping a http URL for, say, an ftp or file URL after creating the object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.