コード例 #1
0
        /// <summary>
        /// Private helper method for creating an asynchronous HttpWebRequests, read the response and post it to a callback.
        /// </summary>
        /// <param name="Uri">Uniform Resource Identifier, HTTP-address of the wanted resource.</param>
        /// <param name="Callback">The callback to be called when the request completes.</param>
        /// <param name="ExceptionCallback">The callback to be called when a request fails.</param>
        /// <remarks>This method merly warps around HttpWebRequest and HttpWebResponse to avoid dublicate code and
        ///  to make future implementation of proxy and different request methods easier. Currently it warps around
        ///  some weird hack, needed to get internet access some places in the world.</remarks>
        private void HttpWebRequest(System.String Uri, HttpWebCallback Callback, HttpExceptionCallback ExceptionCallback)
        {
            //Create a HttpWebRequest
            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Uri);

            //Weird hack to make sure this works in other parts of the world too
            Request.Accept = "*/*";
            /*
             * This is somehow needed because some routhers and/or internet connections requires a useragent.
             * Don't know why exactly, but this solves the problem have a look at 72 issue for futher information:
             * http://code.google.com/p/thelastripper/issues/detail?id=72
             *  */

            //Start the asynchronous request
            Request.BeginGetResponse(new AsyncCallback(this.HttpWebResponse), new System.Object[]{Request, Callback, ExceptionCallback});
        }