Beispiel #1
0
        /// <summary>
        /// Sends post data to back-end request
        /// </summary>
        protected virtual void ApplyPostDataToRequest(WebRequest webRequest)
        {
            // Only if this is post
            if (WebMethods.IsMethod(RequestInfo.RequestMethod, WebMethods.DefaultMethods.POST))
            {
                if (RequestInfo.InputStream != null)
                {
                    Stream reqStream = webRequest.GetRequestStream();

                    // Read stream then reset renamed ViewState name to default
                    byte[] inputBytes = Common.AspDotNetViewStateResetToDef(RequestInfo.InputStream);

                    // Write to destination stream
                    reqStream.Write(inputBytes, 0, inputBytes.Length);
                    reqStream.Close();

                    RequestInfo.InputStream.Close();
                }
                else
                {
                    string postData = Common.AspDotNetViewStateResetToDef(RequestInfo.PostDataString);

                    byte[] bytes = Encoding.ASCII.GetBytes(postData);
                    webRequest.ContentLength = bytes.LongLength;

                    Stream reqStream = webRequest.GetRequestStream();
                    reqStream.Write(bytes, 0, bytes.Length);
                    reqStream.Close();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the request info post data.
        /// </summary>
        protected virtual void IntializeRequestInfoPostData(HttpRequest httpRequest)
        {
            if (httpRequest != null)
            {
                // TODO: test this case
                // When a post back event occurred "httpRequest.ContentType" contains ContentType of request
                // In other cases the "httpRequest.ContentType" is empty and we shouldn't use this property
                if (!string.IsNullOrEmpty(httpRequest.ContentType))
                {
                    RequestInfo.SetContentType(httpRequest.ContentType);
                }

                RequestInfo.InputStream = httpRequest.InputStream;


                // Get posted form data string
                string httpRequestMethod = httpRequest.HttpMethod;

                if (WebMethods.IsMethod(httpRequestMethod, WebMethods.DefaultMethods.POST))
                {
                    RequestInfo.PostDataString = httpRequest.Form.ToString();

                    // Some web sites encodes the url, and we need to decode it.
                    //RequestInfo.PostDataString = HttpUtility.HtmlDecode(RequestInfo.PostDataString);

                    // Since V5.5
                    // The text should be decoded before any use
                    RequestInfo.PostDataString = UnicodeUrlDecoder.UrlDecode(RequestInfo.PostDataString);

                    // BUG: not working with (#) and (&) characters
                    //RequestInfo.PostDataString = HttpUtility.UrlDecode(RequestInfo.PostDataString);
                }
                else
                {
                    RequestInfo.PostDataString = "";
                }
            }
            else
            {
                RequestInfo.PostDataString = "";
            }


            // If requested method is GET
            if (WebMethods.IsMethod(RequestInfo.RequestMethod, WebMethods.DefaultMethods.GET))
            {
                // Apply filter for ASP.NET pages

                // Change requested url by posted data
                RequestInfo.RequestUrl = UrlBuilder.AppendAntoherQueries(RequestInfo.RequestUrl, RequestInfo.PostDataString);
            }
        }