コード例 #1
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="url">The URL for the request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <param name="callBack">The call-back to invoke after the request is complete, if null this method is synchronous.</param>
        /// <param name="state">The state information, ignored if callBack is null.</param>
        internal static byte[] Post(Uri url, OneAllMethod method, Credential creds, byte[] data, BinaryReceivedHandler callBack, object state)
        {
            byte[] retVal = null;

            if (callBack == null) { retVal = PostSync(url, method, creds, data); }
            else { PostAsync(url, method, creds, data, callBack, state); }

            return retVal;
        }
コード例 #2
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="callBack">The call-back to invoke after the request is complete.</param>
 /// <param name="state">The initial state object provided.</param>
 private static void GetAsync(HttpWebRequest request, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     request.BeginGetResponse(OnRequestCompleted, new BinaryWebClientState()
     {
         Request = request,
         Callback = callBack,
         State = state
     });
 }
コード例 #3
0
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="callBack">The call-back to invoke after the request is complete.</param>
 /// <param name="state">The initial state object provided.</param>
 private static void GetAsync(HttpWebRequest request, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     request.BeginGetResponse(OnRequestCompleted, new BinaryWebClientState()
     {
         Request  = request,
         Callback = callBack,
         State    = state
     });
 }
コード例 #4
0
ファイル: WebExtensions.cs プロジェクト: K232/OneAll
 /// <summary>Sets the request for the appropriate HTTP method based on the <see cref="OneAllMethod" />.</summary>
 /// <param name="request">The request.</param>
 /// <param name="method">The OneAll method.</param>
 internal static void SetHTTPMethod(this HttpWebRequest request, OneAllMethod method)
 {
     if (request != null && Enum.IsDefined(typeof(OneAllMethod), method))
     {
         switch (method)
         {
             case OneAllMethod.Invalid: { throw new ArgumentException(OneAllConstants.ERR_INVALID_HTTP_METHOD, OneAllConstants.PARAM_METHOD); };
             default: { request.Method = method.ToString().ToUpper(CultureInfo.InvariantCulture); } break;
         }
     }
     else { throw new ArgumentException(OneAllConstants.ERR_INVALID_HTTP_METHOD, OneAllConstants.PARAM_METHOD); }
 }
コード例 #5
0
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <param name="callBack">The call-back to invoke after the request is complete.</param>
        /// <param name="state">The initial state object provided.</param>
        private static void PostAsync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data, BinaryReceivedHandler callBack, object state)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            request.BeginGetRequestStream(OnRequestStreamObtained, new BinaryWebClientState()
            {
                Request  = request,
                Callback = callBack,
                State    = state,
                Data     = data
            });
        }
コード例 #6
0
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="url">The URL for the request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <param name="callBack">The call-back to invoke after the request is complete, if null this method is synchronous.</param>
        /// <param name="state">The state information, ignored if callBack is null.</param>
        internal static byte[] Post(Uri url, OneAllMethod method, Credential creds, byte[] data, BinaryReceivedHandler callBack, object state)
        {
            byte[] retVal = null;

            if (callBack == null)
            {
                retVal = PostSync(url, method, creds, data);
            }
            else
            {
                PostAsync(url, method, creds, data, callBack, state);
            }

            return(retVal);
        }
コード例 #7
0
        /// <summary>Sets the request for the appropriate HTTP method based on the <see cref="OneAllMethod" />.</summary>
        /// <param name="request">The request.</param>
        /// <param name="method">The OneAll method.</param>
        internal static void SetHTTPMethod(this HttpWebRequest request, OneAllMethod method)
        {
            if (request != null && Enum.IsDefined(typeof(OneAllMethod), method))
            {
                switch (method)
                {
                case OneAllMethod.Invalid: { throw new ArgumentException(OneAllConstants.ERR_INVALID_HTTP_METHOD, OneAllConstants.PARAM_METHOD); };

                default: { request.Method = method.ToString().ToUpper(CultureInfo.InvariantCulture); } break;
                }
            }
            else
            {
                throw new ArgumentException(OneAllConstants.ERR_INVALID_HTTP_METHOD, OneAllConstants.PARAM_METHOD);
            }
        }
コード例 #8
0
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <returns>The binary data from the request.</returns>
        private static byte[] PostSync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            using (Stream stream = request.GetRequestStream())
            {
                byte[] buffer = new byte[data.Length];
                Array.Copy(data, buffer, buffer.Length);

                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();

                Array.Clear(buffer, 0, buffer.Length);
                buffer = null;
            }

            return(ReadResponse(request));
        }
コード例 #9
0
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="callBack">The call-back to invoke after the request is complete.</param>
 /// <param name="state">The state information.</param>
 private static void GetAsync(Uri url, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
 {
     GetAsync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds, callBack, state);
 }
コード例 #10
0
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="data">The raw data to be posted.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] PostSync(Uri url, OneAllMethod method, Credential creds, byte[] data)
 {
     return(PostSync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds, data));
 }
コード例 #11
0
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] GetSync(HttpWebRequest request, OneAllMethod method, Credential creds)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     return(ReadResponse(request));
 }
コード例 #12
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="data">The raw data to be posted.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] PostSync(Uri url, OneAllMethod method, Credential creds, byte[] data)
 {
     return PostSync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds, data);
 }
コード例 #13
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] GetSync(HttpWebRequest request, OneAllMethod method, Credential creds)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     return ReadResponse(request);
 }
コード例 #14
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] GetSync(Uri url, OneAllMethod method, Credential creds)
 {
     return GetSync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds);
 }
コード例 #15
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="callBack">The call-back to invoke after the request is complete.</param>
 /// <param name="state">The state information.</param>
 private static void GetAsync(Uri url, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
 {
     GetAsync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds, callBack, state);
 }
コード例 #16
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <returns>The binary data from the request.</returns>
        private static byte[] PostSync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            using (Stream stream = request.GetRequestStream())
            {
                byte[] buffer = new byte[data.Length];
                Array.Copy(data, buffer, buffer.Length);

                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();

                Array.Clear(buffer, 0, buffer.Length);
                buffer = null;
            }

            return ReadResponse(request);
        }
コード例 #17
0
 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="url">The URL for the request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] GetSync(Uri url, OneAllMethod method, Credential creds)
 {
     return(GetSync(HttpWebRequest.Create(url) as HttpWebRequest, method, creds));
 }
コード例 #18
0
ファイル: BinaryWebClient.cs プロジェクト: K232/OneAll
        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <param name="callBack">The call-back to invoke after the request is complete.</param>
        /// <param name="state">The initial state object provided.</param>
        private static void PostAsync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data, BinaryReceivedHandler callBack, object state)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            request.BeginGetRequestStream(OnRequestStreamObtained, new BinaryWebClientState()
            {
                Request = request,
                Callback = callBack,
                State = state,
                Data = data
            });
        }