internal UploadStringCompletedEventArgs(INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs e)
 {
     Result    = e.Result;
     UserState = e.UserState;
     Error     = e.Error;
     Cancelled = e.Cancelled;
 }
        private void SetEventArgs(INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs e)
        {
            int currentReadyState = GetCurrentReadyState((object)_xmlHttpRequest);
            int currentStatus     = GetCurrentStatus((object)_xmlHttpRequest);

            if (currentStatus == 404)
            {
                e.Error = new Exception("Page not found");
            }
            else if (currentReadyState == 0 && !e.Cancelled)
            {
                e.Error = new Exception("Request not initialized");
            }
            else if ((currentStatus == 0 && !GetIsFileProtocol()) && (currentReadyState == 4 || currentReadyState == 1)) //Note: we check whether the file protocol is file: because apparently, browsers return 0 as the status on a successful call.
            {
                e.Error = new Exception("An error occured. Please make sure that the target Url is available.");
            }
            else if (currentReadyState == 1 && !e.Cancelled)
            {
                e.Error = new Exception("An Error occured. Cross-Site Http Request might not be allowed at the target Url. If you own the domain of the Url, consider adding the header \"Access-Control-Allow-Origin\" to enable requests to be done at this Url.");
            }
            else if (currentReadyState != 4)
            {
                e.Error = new Exception("An Error has occured while submitting your request.");
            }
            e.Result = GetResult((object)_xmlHttpRequest);
        }
        private void SetEventArgs(INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs e)
        {
            int currentReadyState = GetCurrentReadyState((object)_xmlHttpRequest);
            int currentStatus     = GetCurrentStatus((object)_xmlHttpRequest);

            if (currentStatus == 404)
            {
                e.Error = new Exception("Page not found");
            }
            else if (currentReadyState == 0 && !e.Cancelled)
            {
                e.Error = new Exception("Request not initialized");
            }
            else if (currentReadyState == 1 && !e.Cancelled)
            {
                e.Error = new Exception("An Error occured. Cross-Site Http Request might not be allowed at the target Url. If you own the domain of the Url, consider adding the header \"Access-Control-Allow-Origin\" to enable requests to be done at this Url.");
            }
            else if (currentReadyState == 4 && currentStatus == 0)
            {
                e.Error = new Exception("An error occured. Please make sure that the target Url is available.");
            }
            else if (currentReadyState != 4)
            {
                e.Error = new Exception("An Error has occured while submitting your request.");
            }
            e.Result = GetResult((object)_xmlHttpRequest);
        }
示例#4
0
 private void OnDownloadStringCompleted(object sender, INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs e)
 {
     e = new INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs();
     SetEventArgs(e);
     if (DownloadStringCompleted != null)
     {
         DownloadStringCompleted(sender, e);
     }
 }
        private void OnDownloadStringCompleted()
        {
            var e = new INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs();

            SetEventArgs(e);
            if (!_isFirstTryAtSendingUnsafeRequest || !IsCrashInPreflight) // if NOT(first unsafe try AND preflight error). The only case we do not want to enter this if is when the request will be resent without credentials.
            {
                if (DownloadStringCompleted != null)
                {
                    DownloadStringCompleted(_sender, e);
                }
            }
            _isFirstTryAtSendingUnsafeRequest = false;
        }
        private void OnDownloadStringCompleted()
        {
            var e = new INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs();

            SetEventArgs(e);
            if (e.Error == null || !_isFirstTryAtSendingUnsafeRequest)
            {
                if (DownloadStringCompleted != null)
                {
                    DownloadStringCompleted(_sender, e);
                }
            }
            _isFirstTryAtSendingUnsafeRequest = false;
        }
        private void SetEventArgs(INTERNAL_WebRequestHelper_JSOnly_RequestCompletedEventArgs e)
        {
            int    currentReadyState = GetCurrentReadyState((object)_xmlHttpRequest);
            int    currentStatus     = GetCurrentStatus((object)_xmlHttpRequest);
            string errorMessage      = null;

            if (GetHasError((object)_xmlHttpRequest))
            {
                //cases where current status represents an error (like 404 for page not found)
                errorMessage = string.Format("{0} - {1}", currentStatus, GetCurrentStatusText((object)_xmlHttpRequest));
            }
            else if (currentReadyState == 0 && !e.Cancelled)
            {
                errorMessage = "Request not initialized";
            }
            else if ((currentStatus == 0 && !GetIsFileProtocol()) && (currentReadyState == 4 || currentReadyState == 1)) //Note: we check whether the file protocol is file: because apparently, browsers return 0 as the status on a successful call.
            {
                errorMessage = "An error occured. Please make sure that the target Url is available.";
            }
            else if (currentReadyState == 1 && !e.Cancelled)
            {
                errorMessage = "An Error occured. Cross-Site Http Request might not be allowed at the target Url. If you own the domain of the Url, consider adding the header \"Access-Control-Allow-Origin\" to enable requests to be done at this Url.";
            }
            else if (currentReadyState != 4)
            {
                errorMessage = "An Error has occured while submitting your request.";
            }
            if (errorMessage != null)
            {
#if OPENSILVER
                Exception exception = new Exception("An Error has occured while submitting your request.");
#else
                WebException exception = new WebException(errorMessage, null, WebExceptionStatus.ProtocolError, new HttpWebResponse(this.GetXmlHttpRequest()));     //todo: put the correct error type depending on the error (I'm guessing we can know what type it should be by using the statuscode. The test with an error 400 bad request I made was a ProtocolError so I put this here.
#endif
                e.Error = exception;
            }
            e.Result = GetResult((object)_xmlHttpRequest);
        }