.Net CF 2.0 HttpWebRequest pre-authentication and sending credentials on first request.

  • I'm attempting to communicate with bit.ly's REST API using their modified version of basic authentication. However in order for this to work HttpWebRequest needs to attach the credentials on the first request, however, HttpWebRequest will not send credentials on the first request and will wait for a 401 before sending any credentials even if PreAuthenticate is set to true (with PreAuthenticate it will send credentials for all subsequent requests).

     I have attempted the following to get HttpGetRequest to work the way bit.ly requires it:

    (1) Send the request in the format http://username:password@api.bi.ly/method .

    Not supported by bit.ly (as this is a fake implementation of basic authentication they only check the header).

    (2) Manually inject the "Authorization" header into the HttpWebRequest.

    Not possible in the .Net CF as the Authorization header is protected and any attempt to modify a protected header value fails and throws an ArgumentException.

    (3) Inherit HttpWebRequest or WebRequest in another class as to implement the required behavior. 

    Not possible as The HttpWebRequest class is registered to service requests for HTTP and HTTPS schemes by default. Attempts to register a different WebRequest descendant for these schemes will fail as duplicate prefixes are not allowed.


    So anyone got any suggestions?

  •  Can you turn off PreAuthenticate after the first request?

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.