Esempio n. 1
0
        /// <summary>
        /// Submits the form, specifying the request data, redirection action, and a range of valid response types.
        /// </summary>
        /// <param name="requestData">Contains the request data in <b>application/x-www-form-urlencoded</b> format.</param>
        /// <param name="autoRedirect"><b>true</b> if the request should be automatically redirected; <b>false</b> otherwise.</param>
        /// <param name="validTypes">Contains a list of acceptable response types.</param>
        /// <returns>The response from the server.</returns>
        /// <remarks>
        /// This overload allows all form request options to be specified.
        /// </remarks>
        protected WebResponse SubmitRequest(string requestData, bool autoRedirect, WebResponseType[] validTypes)
        {
            WebRequest request;

            if (Attributes.ContainsKey("method") && Attributes["method"].ToUpperInvariant() == "POST")
            {
                request = new PostWebRequest(ActionUrl, requestData, autoRedirect);
            }
            else
            {
                var builder = new UriBuilder(ActionUrl)
                {
                    Query = requestData,
                    Port  = -1
                };

                request = new GetWebRequest(builder.Uri, autoRedirect);
            }

            request.IsXmlHttpRequest = SubmitAsXmlHttpRequest;

            if (FormUrl != null)
            {
                request.Headers.Add(CommonHeaders.Referer, FormUrl.ToString());
            }

            return(WebResponseValidator.ValidateResponse(WebClient.SendRequest(request), validTypes, string.Format(CultureInfo.CurrentCulture, NScrapeResources.UnexpectedResponseOnFormSubmission, request.Destination)));
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            string section = "Ecyware.GreenBlue.ScriptingData";
            Hashtable handler = new Hashtable();
            handler.Add(section, typeof(Ecyware.GreenBlue.Protocols.Http.Scripting.SessionRequestSerializer));

            ConfigManager.SetSectionHandlersOverrides(handler);
            ConfigManager.SetConfigurationFilePathOverrides("C:\\Tester.xml");

            HttpProperties client = new HttpProperties();
            client.UserAgent = "Mozilla";
            client.Pipeline = true;
            client.Referer = "";

            try
            {
                ScriptingData sd = new ScriptingData();
                GetWebRequest sr01 = new GetWebRequest();
                sr01.Url = "http://www.hotmail.com";
                sr01.RequestHttpSettings = client;
                //WebHeader.FillWebHeaderCollection(coll, sr01.RequestHeaders);
                sd.AddWebRequest(sr01);

                //System.Security.Permissions.SecurityPermission perm = new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter);

                XmlNode node = ConfigManager.WriteXmlNode(section, sd);
                MessageBox.Show(node.OuterXml);
            }
            catch ( Exception ex )
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Submits the form, specifying the request data, redirection action, and a range of valid response types.
        /// </summary>
        /// <param name="requestData">Contains the request data in <b>application/x-www-form-urlencoded</b> format.</param>
        /// <param name="autoRedirect"><b>true</b> if the request should be automatically redirected; <b>false</b> otherwise.</param>
        /// <param name="validTypes">Contains a list of acceptable response types.</param>
        /// <returns>The response from the server.</returns>
        /// <remarks>
        /// This overload allows all form request options to be specified.
        /// </remarks>
        protected WebResponse SubmitRequest( string requestData, bool autoRedirect, WebResponseType[] validTypes )
        {
            WebRequest request;

            if ( Attributes.ContainsKey( "method" ) && Attributes["method"].ToUpperInvariant() == "POST" ) {
                request = new PostWebRequest( ActionUrl, requestData, autoRedirect );
            }
            else {
                var builder = new UriBuilder( ActionUrl ) {
                    Query = requestData,
                    Port = -1
                };

                request = new GetWebRequest( builder.Uri, autoRedirect );
            }

            request.IsXmlHttpRequest = SubmitAsXmlHttpRequest;

            if (FormUrl != null) {
                request.Headers.Add(CommonHeaders.Referer, FormUrl.ToString());
            }

            return WebResponseValidator.ValidateResponse( WebClient.SendRequest( request ), validTypes, string.Format( CultureInfo.CurrentCulture, NScrapeResources.UnexpectedResponseOnFormSubmission, request.Destination ) );
        }
        private void SaveSessionAsScriptingData(string fileName)
        {
            try
            {
                ScriptingApplication sd = new ScriptingApplication();

                foreach (SessionRequest req in WebSession.SessionRequests )
                {
                    if ( req.RequestType == HttpRequestType.GET )
                    {
                        GetWebRequest getRequest = new GetWebRequest((GetSessionRequest)req);
                        sd.AddWebRequest(getRequest);
                    }
                    else if ( req.RequestType == HttpRequestType.POST )
                    {
                        PostWebRequest postRequest = new PostWebRequest((PostSessionRequest)req);
                        sd.AddWebRequest(postRequest);
                    }
                }

                sd.Save(fileName);
            }
            catch ( Exception ex )
            {
                MessageBox.Show(ex.ToString());
            }
        }