コード例 #1
0
        /// <summary>
        /// Sends POST Requests.
        /// </summary>
        /// <param name="postUri"> Post uri.</param>
        /// <param name="values"> Values to post.</param>
        /// <param name="stateData"> ResponseBuffer from site.</param>
        /// <param name="cookies"> Cookies from site.</param>
        /// <param name="formTag"> The HtmlFormTag value.</param>
        private void GetPostRequest(string postUri,ArrayList values,ResponseBuffer stateData, CookieCollection cookies, HtmlFormTag formTag)
        {
            // disable
            DisableFormView();

            // add Messaging
            ShowPostRequestMessage(postUri);

            if ( values != null )
                ShowPostedData(values);

            try
            {
                InitializeHttpCommands();
                postForm.ProxySettings = this.ProxySettings;

                if ( formTag.Enctype.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "multipart/form-data" )
                {
                    HttpRequestResponseContext context = new HttpRequestResponseContext();
                    PostWebRequest postReq = new PostWebRequest();
                    postReq.Form.ReadHtmlFormTag(formTag);
                    Ecyware.GreenBlue.Engine.Scripting.Cookies c = new Cookies(cookies);
                    postReq.Cookies =  c.GetCookies();
                    postReq.RequestType = HttpRequestType.POST;
                    postReq.Url = postUri;
                    postReq.RequestHttpSettings = this.GetHttpPropertiesFromPanel();
                    context.Request = postReq;

                    postForm.StartAsyncHttpPostFileUpload(context);
                }
                else
                {
                    postForm.StartAsyncHttpPost(postUri,this.GetHttpPropertiesFromPanel(),values,cookies);
                }
            }
            catch ( Exception ex )
            {
                this.txtMessaging.SelectionColor = Color.Red;
                this.txtMessaging.SelectedText = "Html Browser Error: " + ex.Message + "\r\n";

                textViewerForm.EditorText = ex.Message;
                // enable
                EnableFormView();
                this.navForm.StopNavigation();
                this.StopProgressBarEvent(this,new ProgressBarControlEventArgs("Ready"));
            }
        }
        /// <summary>
        /// Creates the web response for the current web request.
        /// </summary>
        private void CreateWebResponse()
        {
            // Get the context
            HttpRequestResponseContext context = ((ScriptingHttpState)HttpStateData).HttpRequestResponseContext;

            // Create a web response
            context.Request.WebResponse = new WebResponse();

            Cookies cookies = new Cookies();
            cookies.AddCookies(HttpResponseData.CookieCollection);

            // Fill the web response
            context.Request.WebResponse.Cookies = cookies.GetCookies();

            context.Request.WebResponse.ErrorMessage = string.Empty;
            context.Request.WebResponse.GetHtmlXml = HttpResponseData.GetHtmlXml;
            context.Request.WebResponse.HttpBody = HttpResponseData.HttpBody;

            context.Request.WebResponse.ResponseHttpSettings = context.Request.RequestHttpSettings.Clone();

            ArrayList headers = new ArrayList();
            //int i = 0;
            foreach ( DictionaryEntry de in HttpResponseData.ResponseHeaderCollection )
            {
                string name = Convert.ToString(de.Key);
                switch ( name.ToLower(System.Globalization.CultureInfo.InvariantCulture) )
                {

                    case "accept":
                        break;
                    case "connection":
                        break;
                    case "content-length":
                        context.Request.WebResponse.ResponseHttpSettings.ContentLength = HttpStateData.HttpResponse.ContentLength;
                        break;
                    case "content-type":
                        context.Request.WebResponse.ResponseHttpSettings.ContentType = HttpStateData.HttpResponse.ContentType;
                        break;
                    case "character set":
                        context.Request.WebResponse.CharacterSet = HttpStateData.HttpResponse.CharacterSet;
                        break;
                    case "content encoding":
                        context.Request.WebResponse.ContentEncoding = HttpStateData.HttpResponse.ContentEncoding;
                        break;
                    case "date":
                        break;
                    case "expect":
                        break;
                    case "host":
                        break;
                    case "if-modified-since":
                        context.Request.WebResponse.ResponseHttpSettings.IfModifiedSince = HttpStateData.HttpResponse.LastModified;
                        break;
                    case "last modified":
                        context.Request.WebResponse.ResponseHttpSettings.IfModifiedSince = HttpStateData.HttpResponse.LastModified;
                        break;
                    case "protocol version":
                        context.Request.WebResponse.Version = HttpResponseData.Version;
                        break;
                    case "range":
                        break;
                    case "referer":
                        break;
                    case "response uri":
                        context.Request.WebResponse.ResponseUri = HttpStateData.HttpResponse.ResponseUri.ToString();
                        break;
                    case "status":
                        break;
                    case "status code":
                        context.Request.WebResponse.StatusCode = HttpResponseData.StatusCode;
                        break;
                    case "status description":
                        context.Request.WebResponse.StatusDescription = HttpStateData.HttpResponse.StatusDescription;
                        break;
                    case "transfer-encoding":
                        break;
                    case "user-agent":
                        break;
                    default:
                        WebHeader header = new WebHeader();
                        header.Name = name;
                        header.Value = Convert.ToString(de.Value);
                        headers.Add(header);
                        break;
                }
            }

            context.Request.WebResponse.ResponseHttpSettings.AdditionalHeaders = (WebHeader[])headers.ToArray(typeof(WebHeader));
            context.Request.WebResponse.Scripts = HttpResponseData.Scripts.ToArray();
        }
コード例 #3
0
        private void UpdateCookies(Ecyware.GreenBlue.Engine.Scripting.WebRequest request)
        {
            PropertyTable bag = (PropertyTable)this.pgCookies.SelectedObject;

            Ecyware.GreenBlue.Engine.Scripting.Cookies editedCookies = new Ecyware.GreenBlue.Engine.Scripting.Cookies();

            foreach ( Ecyware.GreenBlue.Engine.Scripting.Cookie cky in request.Cookies)
            {
                CookieWrapperExtended cookieWrapper = (CookieWrapperExtended)bag[cky.Name];
                editedCookies.CookieList().Add(cookieWrapper.GetCookie());
            }

            request.ClearCookies();
            request.Cookies = editedCookies.GetCookies();
        }