コード例 #1
0
        /// <summary>
        /// Returns the http properties from the property grid.
        /// </summary>
        /// <returns> A HttpProperties.</returns>
        public HttpProperties GetHttpProperties()
        {
            HttpProperties props = new HttpProperties();
            PropertyTable bag = (PropertyTable)this.pgHeaders.SelectedObject;
            props.Accept = (string)bag["Accept"];

            if ( this.RequestHeaders.AuthenticationSettings.UseBasicAuthentication )
            {
                props.AuthenticationSettings = this.RequestHeaders.AuthenticationSettings;
            }
            else
            {
                props.AuthenticationSettings.UseNTLMAuthentication = this.RequestHeaders.AuthenticationSettings.UseNTLMAuthentication;
            }

            props.ContentLength = Convert.ToInt64(bag["Content Length"]);
            props.ContentType = (string)bag["Content Type"];
            props.IfModifiedSince = Convert.ToDateTime(bag["If Modified Since"]);
            props.KeepAlive = (bool)bag["Keep Alive"];
            props.MediaType = (string)bag["Media Type"];
            props.Pipeline = (bool)bag["Pipeline"];
            props.Referer = (string)bag["Referer"];
            props.SendChunked = (bool)bag["Send Chunked"];
            props.TransferEncoding = (string)bag["Transfer Encoding"];
            props.UserAgent = (string)bag["User Agent"];
            props.Timeout = (int)bag["Timeout"];

            return props;
        }
        /// <summary>
        /// Creates a new InspectorPipelineCommand.
        /// </summary>
        /// <param name="clientSettings"> The HTTP Properties.</param>
        /// <param name="proxySettings"> The HTTP Proxy settings.</param>
        /// <param name="httpState"> The HTTP State.</param>
        /// <param name="callback"> The callback method.</param>
        public InspectorPipelineCommand(HttpProperties clientSettings, HttpProxy proxySettings, HttpState httpState, Delegate callback)
        {
            Initialize();

            inspectorPipeline.ClientSettings = clientSettings;
            inspectorPipeline.ProxySettings = proxySettings;
            HttpStateData = httpState;
            CallbackMethod = callback;
        }
コード例 #3
0
        /// <summary>
        /// Fills the ResponseBuffer.
        /// </summary>
        /// <param name="response"> The HttpWebResponse type.</param>
        /// <param name="hwr"> The HttpWebRequest type.</param>
        /// <param name="clientSettings"> The http settings.</param>
        /// <param name="httpState"> The Http state.</param>
        /// <returns> A ResponseBuffer type.</returns>
        internal static ResponseBuffer FillResponseBuffer(HttpWebResponse response, HttpWebRequest hwr, HttpProperties clientSettings, HttpState httpState)
        {
            ResponseBuffer respBuffer = null;

            if ( CompareString.Compare(hwr.Method,"get") )
            {
                respBuffer = new ResponseBuffer(HttpRequestType.GET);
            }
            else
            {
                respBuffer = new ResponseBuffer(HttpRequestType.POST);
            }

            respBuffer.StatusCode = (int)response.StatusCode;
            respBuffer.StatusDescription=response.StatusDescription;

            if ( response.ProtocolVersion == HttpVersion.Version11  )
            {
                respBuffer.Version="1.1";
            }
            else
            {
                respBuffer.Version="1.0";
            }

            // Request Header Collection
            BufferBuilder.FillRequestHeader(respBuffer,hwr.Headers,hwr);

            // Header Collection
            BufferBuilder.FillResponseHeader(respBuffer,hwr,response.Headers,response);

            // Cookie collection
            response.Cookies = hwr.CookieContainer.GetCookies(hwr.RequestUri);
            BufferBuilder.FillCookieData(respBuffer,response.Cookies);

            Stream stm = response.GetResponseStream();
            BufferBuilder.FillHttpBody(respBuffer,stm);
            stm.Close();

            if ( response!=null )
            {
                response.Close();
            }

            return respBuffer;
        }
コード例 #4
0
        /// <summary>
        /// Creates a new SoftTestCommand.
        /// </summary>
        /// <param name="url"> The url to apply the test.</param>
        /// <param name="form"> The form to apply the tests.</param>
        /// <param name="proxySettings"> The http proxy settings.</param>
        /// <param name="httpProperties"> The http settings.</param>
        /// <param name="sqlTest"> The sql test to use.</param>
        /// <param name="xssTest"> The xss test to use.</param>
        /// <param name="bufferLength"> The buffer overflow length to use.</param>
        public SoftTestCommand(Uri url,
			HtmlFormTag form,
			HttpProxy proxySettings,
			HttpProperties httpProperties,
			string sqlTest,
			string xssTest,
			int bufferLength)
            : this()
        {
            this._xssSignature = xssTest;
            this._sqlSignature = sqlTest;
            this._bufferLen = bufferLength;

            this.Url = url;
            this.FormTag = form;
            this.Proxy = proxySettings;
            this.ProtocolProperties = httpProperties;

            //			updateElementNames.Add("__VIEWSTATE");
            //			updateElementNames.Add("__EVENTTARGET");
        }
コード例 #5
0
        /// <summary>
        /// Adds the request headers to the report.
        /// </summary>
        /// <param name="parentRow"> The ResponseDocumentRow.</param>
        /// <param name="report"> The HtmlUnitTestReport type.</param>
        /// <param name="responseBuffer"> The response buffer.</param>
        /// <param name="httpProperties"> The Http Properties type.</param>
        private void AddRequestHeaders(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, ResponseBuffer responseBuffer, HttpProperties httpProperties)
        {
            Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.RequestHeaderRow reqHeaderRow = report.RequestHeader.NewRequestHeaderRow();

            reqHeaderRow.SetParentRow(parentRow);
            report.RequestHeader.AddRequestHeaderRow(reqHeaderRow);

            Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.RequestItemsRow row = null;

            if ( httpProperties.Accept != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "Accept";
                row.Value = httpProperties.Accept;
                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }

            row = report.RequestItems.NewRequestItemsRow();
            row.Name = "Content length";
            row.Value = httpProperties.ContentLength.ToString();
            row.SetParentRow(reqHeaderRow);
            report.RequestItems.AddRequestItemsRow(row);

            if ( httpProperties.ContentType != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "Content type";
                row.Value = httpProperties.ContentType;
                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }

            row = report.RequestItems.NewRequestItemsRow();
            row.Name = "If modified since";
            row.Value = httpProperties.IfModifiedSince.ToString();
            row.SetParentRow(reqHeaderRow);
            report.RequestItems.AddRequestItemsRow(row);

            row = report.RequestItems.NewRequestItemsRow();
            row.Name = "Keep alive";
            row.Value = httpProperties.KeepAlive.ToString();
            row.SetParentRow(reqHeaderRow);
            report.RequestItems.AddRequestItemsRow(row);

            if ( httpProperties.MediaType != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "Media type";
                row.Value = httpProperties.MediaType;
                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }

            row = report.RequestItems.NewRequestItemsRow();
            row.Name = "Pipeline";
            row.Value = httpProperties.Pipeline.ToString();
            row.SetParentRow(reqHeaderRow);
            report.RequestItems.AddRequestItemsRow(row);

            if ( httpProperties.Referer != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "Referer";
                row.Value = httpProperties.Referer;
                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }

            row = report.RequestItems.NewRequestItemsRow();
            row.Name = "Send chunked";
            row.Value = httpProperties.SendChunked.ToString();
            row.SetParentRow(reqHeaderRow);
            report.RequestItems.AddRequestItemsRow(row);

            if ( httpProperties.TransferEncoding != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "Transfer encoding";
                row.Value = httpProperties.TransferEncoding;
                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }

            if ( httpProperties.UserAgent != null )
            {
                row = report.RequestItems.NewRequestItemsRow();
                row.Name = "User agent";
                row.Value = httpProperties.UserAgent;

                row.SetParentRow(reqHeaderRow);
                report.RequestItems.AddRequestItemsRow(row);
            }
        }
コード例 #6
0
        /// <summary>
        /// Fills the workspace with data retrieve from site.
        /// </summary>
        /// <param name="response">ResponseBuffer</param>
        public void FillWorkspace(ResponseBuffer response)
        {
            if (response.ErrorMessage != String.Empty)
            {
                // reset statusbar
                ChangeStatusBarPanelEvent(this, CleanStatusArgs);

                this.txtMessaging.SelectionColor = Color.Red;
                this.txtMessaging.SelectedText = "Html Browser Error: " + response.ErrorMessage  + "\r\n";

                // Show Error
                textViewerForm.EditorText  = response.ErrorMessage;

                // Stop progress
                this.StopProgressBarEvent(this, new ProgressBarControlEventArgs("Ready"));

                this.InspectorState = GBInspectorState.Error;
            }
            else
            {
                // Set Editor Text
                try
                {
                    textViewerForm.EditorText = response.HttpBody;

                    // save buffer, do not save before error message check
                    this.CurrentResponseBuffer = response;

                    // load forms editor if any
                    if ( formCollection != null )
                    {
                        DisplayForms(formCollection, false);
                    }

                    Uri responseUri = (Uri)response.ResponseHeaderCollection["Response Uri"];

                    // Get Settings from Panel
                    ClientProperties = this.GetHttpPropertiesFromPanel();

                    // Update referer
                    ClientProperties.Referer = responseUri.ToString();

                    // Load properties
                    LoadHttpProperties(this.ClientProperties);

                    // Add to history
                    AddToHistory(response);

                    //					// Add to cookies
                    //					cookieManager.AddCookies(response.CookieCollection);

                    // Fill Lists
                    FillListViews(response);
                    FillCookieListView(response.CookieCollection);

                    // Update address bar
                    RequestGetEventArgs requestArgs = new RequestGetEventArgs();
                    requestArgs.Url = responseUri.ToString();
                    this.UpdateAddressEvent(this, requestArgs);

                    // Update Session Request
                    UpdateSessionRequest(response);

                    EnableFormView();
                    this.InspectorState = GBInspectorState.Complete;

                    // Stop progress only if navigator CanLinkNavigate is true.
                    if ( navForm.CanLinkNavigate )
                    {
                        // reset statusbar
                        ChangeStatusBarPanelEvent(this, CleanStatusArgs);
                        // stop progress bar
                        this.StopProgressBarEvent(this,new ProgressBarControlEventArgs("Ready"));
                    }

                    // Location is found in Hashtable
                    if ( response.ResponseHeaderCollection.ContainsKey("Location") )
                    {
                        // Location is not empty
                        if ( ((string)response.ResponseHeaderCollection["Location"])!=String.Empty )
                        {
                            // Apply direct and log in recording sesion if any.
                            this.ApplyUrlRedirection();

                            // navForm.PendingRedirection = true;
                            //ChangeStatusBarPanelEvent(this,RedirectMessageArgs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string message = ExceptionHandler.RegisterException(ex);
                    MessageBox.Show(message,AppLocation.ApplicationName, MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Loads the application options.
        /// </summary>
        /// <param name="sender"> The sender object.</param>
        /// <param name="e"> The event arguments.</param>
        private void LoadApplicationOptions(object sender, EventArgs e)
        {
            ApplicationOptions appOptions = new ApplicationOptions();
            appOptions.ClientSettings = ClientProperties;
            appOptions.ApplicationSettings = InspectorConfig;

            if ( appOptions.ShowDialog() == DialogResult.OK )
            {
                ClientProperties = appOptions.ClientSettings;
                InspectorConfig = appOptions.ApplicationSettings;
            }

            LoadApplicationProperties(InspectorConfig);
            LoadHttpProperties(ClientProperties);
        }
コード例 #8
0
        /// <summary>
        /// Initializes the form.
        /// </summary>
        private void InitializeForm()
        {
            // sets the IsUnique for the tab document
            this.IsUnique = true;

            // init settings types
            this.SnifferProperties = new SnifferOptions();

            // get settings
            InspectorConfig = (InspectorConfiguration)ConfigManager.Read("greenBlue/inspector", false);
            ClientProperties = (HttpProperties)ConfigManager.Read("greenBlue/httpClient", false);

            // Load Application Properties
            LoadApplicationProperties(InspectorConfig);

            // Load Http Properties
            LoadHttpProperties(ClientProperties);

            // Init Get and Post Command
            InitializeHttpCommands();

            // Start event for GBInspectorWorkspace
            this.StartEventDelegate += new InspectorStartRequestEventHandler(InspectorStartGetEvent);
            this.CancelEventDelegate += new InspectorCancelRequestEventHandler(InspectorCancelRequestEvent);

            // get request event
            textViewerForm.StartEvent += new InspectorStartRequestEventHandler(InspectorStartGetEvent);

            // Context menu
            textViewerForm.txtEditor.ContextMenu = this.mnuTextStream;
            textViewerForm.txtEditor.TextChanged += new EventHandler(txtHTTPStream_TextChanged);
            textViewerForm.txtEditor.CaretChange += new EventHandler(txtEditor_CaretChange);

            // Create browser
            navForm = new NavigableWebForm();
            AttachWebFormEvents(navForm);

            // Add browser
            DocumentManager.Document navigatorDoc = new DocumentManager.Document(navForm,"Web Browser");
            dmDocuments.AddDocument(navigatorDoc);

            // Add Html Text Editor
            htmlEditorDocument = new DocumentManager.Document(textViewerForm,"Html Browser");
            dmDocuments.AddDocument(htmlEditorDocument);

            // Load History Tree
            this.sitesTree.ImageList = this.imgIcons;
            this.sitesTree.IconNodeIndex = 1;
            this.sitesTree.IconSiteIndex = 7;
            this.sitesTree.LoadHistoryTree();
        }
コード例 #9
0
        /// <summary>
        /// Get Async get request.
        /// </summary>
        /// <param name="getUrl"> The url.</param>
        /// <param name="values"> The get values.</param>
        /// <param name="cookies"> The cookies.</param>
        /// <param name="state"> The http state.</param>
        private void StartGetRequest(GetForm httpCommand, string getUrl, ArrayList values, CookieCollection cookies, HttpProperties settings, HttpState state)
        {
            try
            {
                httpCommand.StartAsyncHttpGet(
                    getUrl,
                    settings,
                    values,
                    cookies,
                    state,
                    false);
            }
            catch (Exception ex)
            {
                // register and show
                ExceptionHandler.RegisterException(ex);

                AbortSessionRun(ex.Message);
            }
        }
コード例 #10
0
        /// <summary>
        /// Begins a new asynchronous HTTP Get request. This function is not thread safe.
        /// </summary>
        /// <param name="uri"> An uri to request.</param>
        /// <param name="properties"> The HttpProperties to set for the request.</param>
        /// <param name="values"> The values to include for a GET request.</param>
        /// <param name="cookies"> The cookies to set for the request.</param>
        /// <param name="httpRequestState"> The HttpState.</param>
        public ResponseBuffer StartSyncHttpGet(string uri, HttpProperties properties, ArrayList values, CookieCollection cookies, HttpState httpRequestState)
        {
            uri = EncodeDecode.UrlDecode(uri);
            uri = EncodeDecode.HtmlDecode(uri);

            try
            {
                //this.ValidateIPAddress(new Uri(uri));

                if ( values != null )
                    uri = AppendToUri(uri,values);

                httpRequestState.HttpRequest = (HttpWebRequest)WebRequest.Create(uri);

                // Set HttpWebRequestProperties
                SetHttpWebRequestProperties(httpRequestState.HttpRequest, properties);

                // Apply proxy settings
                if ( this.ProxySettings != null )
                {
                    SetProxy(httpRequestState.HttpRequest,this.ProxySettings);
                }

                // save cookies
                httpRequestState.HttpRequest.CookieContainer=new CookieContainer();
                if ( cookies!=null )
                {
                    httpRequestState.HttpRequest.CookieContainer.Add(cookies);
                }

                HttpWebResponse httpResponse = (HttpWebResponse)httpRequestState.HttpRequest.GetResponse();
                httpRequestState.HttpResponse = httpResponse;

                // get ResponseBuffer
                ResponseBuffer responseBuffer = HttpPipeline.FillResponseBuffer(httpResponse,
                    httpRequestState.HttpRequest,
                    properties,
                    httpRequestState);

                return responseBuffer;
            }
            catch
            {
                throw;
            }
            finally
            {
                if ( httpRequestState.HttpResponse != null )
                {
                    httpRequestState.HttpResponse.Close();
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Sets the HttpWebRequest properties.
        /// </summary>
        /// <param name="hwr"> The HttpWebRequest type.</param>
        /// <param name="properties"> The HttpProperties type that contains the values to set.</param>
        protected void SetHttpWebRequestProperties(HttpWebRequest hwr, HttpProperties properties)
        {
            // SSL/TLS Certificates Policy Settings
            ServicePointManager.CertificatePolicy = new SSLCertificatePolicy();

            // Security Protocol Settings
            ServicePointManager.SecurityProtocol = properties.SecurityProtocol;

            this.ClientSettings = properties;

            hwr.AllowAutoRedirect = properties.AllowAutoRedirects;
            hwr.MaximumAutomaticRedirections = properties.MaximumAutoRedirects;
            hwr.AllowWriteStreamBuffering = properties.AllowWriteStreamBuffering;
            hwr.UserAgent = properties.UserAgent;
            hwr.Pipelined = properties.Pipeline;
            hwr.SendChunked = properties.SendChunked;
            hwr.KeepAlive = properties.KeepAlive;
            hwr.Accept = properties.Accept;

            if ( properties.ContentLength > -1 )
            {
                hwr.ContentLength = properties.ContentLength;
            }

            hwr.ContentType = properties.ContentType;
            hwr.IfModifiedSince = properties.IfModifiedSince;
            hwr.MediaType = properties.MediaType;
            hwr.TransferEncoding = properties.TransferEncoding;
            hwr.Referer= properties.Referer;

            foreach ( WebHeader wh in properties.AdditionalHeaders )
            {
                hwr.Headers.Add(wh.Name, wh.Value);
            }

            // authentication
            HttpAuthentication auth = properties.AuthenticationSettings;

            // set Windows NTLM security
            if ( auth.UseNTLMAuthentication )
            {
                hwr.Credentials = CredentialCache.DefaultCredentials;
                hwr.UnsafeAuthenticatedConnectionSharing = true;

            }
            else
            {
                // use basic authentication
                if ( auth.UseBasicAuthentication )
                {
                    if ( auth.Domain != String.Empty )
                    {
                        hwr.Credentials=new NetworkCredential(auth.Username,auth.Password,auth.Domain);
                    }
                    else
                    {
                        hwr.Credentials=new NetworkCredential(auth.Username,auth.Password);
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Loads scripts with SRC attribute and adds it to the Script Collection in ResponseBuffer.
        /// </summary>
        /// <param name="requestUrl"> The top url.</param>
        /// <param name="response"> The ResponseBuffer.</param>
        /// <param name="clientSettings"> The http settings.</param>
        /// <returns> An updated ResponseBuffer.</returns>
        internal static ResponseBuffer LoadScriptsFromSrc(Uri requestUrl,ResponseBuffer response,HttpProperties clientSettings)
        {
            GetForm http = new GetForm();
            HtmlScriptCollection scripts = response.Scripts;

            for (int i=0;i<scripts.Count;i++)
            {
                if ( scripts[i].Source.Length!=0 )
                {
                    string src = scripts[i].Source;
                    string requestData = string.Empty;

                    requestData = UriResolver.ResolveUrl(requestUrl,src);

                    // add User Agent
                    clientSettings.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0)";

                    try
                    {
                        // load
                        ResponseBuffer result = http.StartSyncHttpGet(requestData,clientSettings,null,response.CookieCollection);

                        scripts[i].Text = result.HttpBody;
                    }
                    catch (Exception ex)
                    {
                        // TODO: Log this errors as SCRIPT loading failed error
                        System.Diagnostics.Debug.Write(ex.Message);
                    }
                }
            }

            return response;
        }
コード例 #13
0
 /// <summary>
 /// Creates a new HttpPropertiesWrapper.
 /// </summary>
 /// <param name="httpProperties"> The HttpProperties object to wrap.</param>
 public HttpPropertiesWrapper(HttpProperties httpProperties)
 {
     _httpProperties = httpProperties;
 }
コード例 #14
0
        /// <summary>
        /// Redirects to url.
        /// </summary>
        /// <param name="state"> The HTTP State.</param>
        /// <param name="cookies"> The cookie collection.</param>
        /// <param name="settings"> The HTTP Settings.</param>
        /// <param name="url"> The url to redirect to.</param>
        private void ApplyUrlRedirection(HttpState state, CookieCollection cookies,HttpProperties settings, string url)
        {
            this.DisplaySessionProcessEvent(this, new SessionCommandProcessEventArgs("Requesting " + url));

            // Request, we only use url, http settings and cookies, because
            // IE doesn't returns and arraylist of values for GET requests.
            this.StartGetRequest(safeSessionGetRequest,url,null, cookies, settings, state);
        }
コード例 #15
0
        /// <summary>
        /// Get Async post request.
        /// </summary>
        /// <param name="postUrl"> The url to post.</param>
        /// <param name="listValues"> The post data values.</param>
        /// <param name="cookies"> The cookies.</param>
        /// <param name="state"> The http state.</param>
        private void StartPostRequest(PostForm httpCommand, string postUrl, ArrayList listValues, CookieCollection cookies,HttpProperties settings, HttpState state)
        {
            try
            {
                httpCommand.StartAsyncHttpPost(
                    postUrl,
                    settings,
                    listValues,
                    cookies, state);
            }
            catch (Exception ex)
            {
                // register and show
                ExceptionHandler.RegisterException(ex);

                AbortSessionRun(ex.Message);
            }
        }
コード例 #16
0
        /// <summary>
        /// Loads the http properties.
        /// </summary>
        /// <param name="httpProperties"> The HttpProperties type.</param>
        public void LoadHttpProperties(HttpProperties httpProperties)
        {
            this.RequestHeaders = httpProperties;

            PropertyTable bag = new PropertyTable();
            string category = "Request Headers";
            // string category2 = "Authentication";

            //PropertySpec item = new PropertySpec("Headers",typeof(HttpPropertiesWrapper),category,"Request Headers");
            PropertySpec accept = new PropertySpec("Accept", typeof(string),category);
            PropertySpec contentLength = new PropertySpec("Content Length",typeof(string), category);
            PropertySpec contentType = new PropertySpec("Content Type",typeof(string), category);
            PropertySpec ifModifiedSince = new PropertySpec("If Modified Since",typeof(DateTime), category);
            PropertySpec keepAlive = new PropertySpec("Keep Alive",typeof(bool), category);
            PropertySpec mediaType = new PropertySpec("Media Type",typeof(string), category);
            PropertySpec pipeline = new PropertySpec("Pipeline",typeof(bool), category);
            PropertySpec referer = new PropertySpec("Referer",typeof(string), category);
            PropertySpec sendChunked = new PropertySpec("Send Chunked",typeof(bool), category);
            PropertySpec transferEncoding = new PropertySpec("Transfer Encoding",typeof(string), category);
            PropertySpec userAgent = new PropertySpec("User Agent",typeof(string), category);
            PropertySpec timeout = new PropertySpec("Timeout",typeof(int), category);

            // PropertySpec addonHeaders = new PropertySpec("Additional headers",typeof(string[]), category);
            // PropertySpec ntlmAuth = new PropertySpec("Windows Integrated Security", typeof(bool), category2);
            // accept.ConverterTypeName = "Ecyware.GreenBlue.Controls.HttpPropertiesWrapper";

            bag.Properties.AddRange(new PropertySpec[] {accept,
                                                           contentLength,
                                                           contentType,
                                                           ifModifiedSince,
                                                           keepAlive,
                                                           mediaType,
                                                           pipeline,
                                                           referer,
                                                           sendChunked,
                                                           transferEncoding,
                                                           userAgent, timeout});

            bag[accept.Name] = httpProperties.Accept;
            bag[contentLength.Name] = httpProperties.ContentLength;
            bag[contentType.Name] = httpProperties.ContentType;
            bag[ifModifiedSince.Name] = httpProperties.IfModifiedSince;
            bag[keepAlive.Name] = httpProperties.KeepAlive;
            bag[mediaType.Name] = httpProperties.MediaType;
            bag[pipeline.Name] = httpProperties.Pipeline;
            bag[referer.Name] = httpProperties.Referer;
            bag[sendChunked.Name] = httpProperties.SendChunked;
            bag[transferEncoding.Name] = httpProperties.TransferEncoding;
            bag[userAgent.Name] = httpProperties.UserAgent;
            bag[timeout.Name] = httpProperties.Timeout;
            //bag[addonHeaders.Name] = new string[0];
            // bag[ntlmAuth.Name] = httpProperties.AuthenticationSettings.UseNTLMAuthentication;

            this.pgHeaders.SelectedObject = bag;
        }
コード例 #17
0
        /// <summary>
        /// Begins a new asynchronous HTTP Post request. This function is not thread safe.
        /// </summary>
        /// <param name="postUri"> The Url string.</param>
        /// <param name="properties"> The HttpProperties to set for the request.</param>
        /// <param name="values"> The data to post.</param>
        /// <param name="cookies"> The cookie data to set for the request.</param>
        /// <param name="httpRequestState"> The HttpState.</param>		
        public void StartAsyncHttpPost(string postUri,HttpProperties properties,ArrayList values, CookieCollection cookies, HttpState httpRequestState)
        {
            //			httpRequestState = new HttpState();
            //			httpRequestState.TestItem = unitTestItem;
            //			httpRequestState.IsLastItem = lastItem;

            postUri = EncodeDecode.UrlDecode(postUri);
            postUri = EncodeDecode.HtmlDecode(postUri);

            // create webrequest
            try
            {
                //this.ValidateIPAddress(new Uri(postUri));

                httpRequestState.HttpRequest = (HttpWebRequest)WebRequest.Create(postUri);

                // Set HttpWebRequestProperties
                SetHttpWebRequestProperties(httpRequestState.HttpRequest, properties);

                // Apply proxy settings
                if ( this.ProxySettings != null )
                {
                    SetProxy(httpRequestState.HttpRequest,this.ProxySettings);
                }

                //httpRequestState.httpRequest.Referer = postUri;

                // Continue headers
                //hwr.ContinueDelegate = getRedirectHeaders;

                // save cookies
                httpRequestState.HttpRequest.CookieContainer=new CookieContainer();

                if ( cookies!=null )
                {
                    httpRequestState.HttpRequest.CookieContainer.Add(cookies);
                }

                byte[] data=null;
                if (values!=null)
                {
                    // transform to postdata and encode in bytes
                    string postData = GetPostData(values);
                    data = Encoding.UTF8.GetBytes(postData);

                    // set properties
                    httpRequestState.HttpRequest.Method="POST";
                    httpRequestState.HttpRequest.ContentType="application/x-www-form-urlencoded";
                    httpRequestState.HttpRequest.ContentLength=data.Length;

                    // get request stream
                    // TODO: async, but in our example we ain't posting files
                    Stream stm = httpRequestState.HttpRequest.GetRequestStream();
                    stm.Write(data,0,data.Length);
                    stm.Flush();
                    stm.Close();
                }

                // Get Response
                IAsyncResult ar = httpRequestState.HttpRequest.BeginGetResponse(new AsyncCallback(FastResponseCallback),httpRequestState);

                // register a timeout
                ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, new WaitOrTimerCallback(BaseHttpForm.RequestTimeoutCallback), httpRequestState, this.GetTimeout(), true);

            }
            catch
            {
                throw;
            }
            finally
            {
                if ( httpRequestState.HttpResponse != null )
                {
                    httpRequestState.HttpResponse.Close();
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Begins a new asynchronous HTTP Get request. This function is not thread safe.
        /// </summary>
        /// <param name="uri"> An uri to request.</param>
        /// <param name="properties"> The HttpProperties to set for the request.</param>
        /// <param name="values"> The values to include for a GET request.</param>
        /// <param name="cookies"> The cookies to set for the request.</param>
        /// <param name="httpRequestState"> Sets the Http State type.</param>
        /// <param name="doDecode"> Decodes the uri with Url and Html.</param>
        public void StartAsyncHttpGet(string uri, HttpProperties properties, ArrayList values, CookieCollection cookies, HttpState httpRequestState, bool doDecode)
        {
            if ( doDecode )
            {
                uri = EncodeDecode.UrlDecode(uri);
                uri = EncodeDecode.HtmlDecode(uri);
            }

            try
            {
                //this.ValidateIPAddress(new Uri(uri));

                if ( values != null )
                {
                    uri = AppendToUri(uri,values);
                }

                httpRequestState.HttpRequest = (HttpWebRequest)WebRequest.Create(uri);

                // Set HttpWebRequestProperties
                SetHttpWebRequestProperties(httpRequestState.HttpRequest, properties);

                // Apply proxy settings
                if ( this.ProxySettings != null )
                {
                    SetProxy(httpRequestState.HttpRequest,this.ProxySettings);
                }
                // Continue headers
                //hwr.ContinueDelegate=getRedirectHeaders;

                // save cookies
                httpRequestState.HttpRequest.CookieContainer=new CookieContainer();
                if ( cookies!=null )
                {
                    httpRequestState.HttpRequest.CookieContainer.Add(cookies);
                }

                //httpRequestState.httpRequest.Referer = uri;
                IAsyncResult ar = httpRequestState.HttpRequest.BeginGetResponse(new AsyncCallback(FastResponseCallback),httpRequestState);

                // register a timeout
                ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, new WaitOrTimerCallback(BaseHttpForm.RequestTimeoutCallback), httpRequestState, this.GetTimeout(), true);
            }
            catch
            {
                throw;
            }
            finally
            {
                if ( httpRequestState.HttpResponse != null )
                {
                    httpRequestState.HttpResponse.Close();
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Starts a new HTTP Post request.
        /// </summary>
        /// <param name="postUri"> The Url string.</param>
        /// <param name="properties"> The HttpProperties to set for the request.</param>
        /// <param name="values"> The data to post.</param>
        /// <param name="cookies"> The cookie data to set for the request.</param>
        /// <returns> A ResponseBuffer type.</returns>
        public ResponseBuffer StartSyncHttpPost(string postUri,HttpProperties properties,ArrayList values, CookieCollection cookies)
        {
            HttpWebResponse response=null;
            ResponseBuffer respBuffer=new ResponseBuffer();
            httpRequestState = new HttpState();

            postUri = EncodeDecode.UrlDecode(postUri);
            postUri = EncodeDecode.HtmlDecode(postUri);

            // create webrequest
            try
            {
                //this.ValidateIPAddress(new Uri(postUri));

                httpRequestState.HttpRequest = (HttpWebRequest)WebRequest.Create(postUri);

                // Set HttpWebRequestProperties
                SetHttpWebRequestProperties(httpRequestState.HttpRequest, properties);

                // Apply proxy settings
                if ( this.ProxySettings != null )
                {
                    SetProxy(httpRequestState.HttpRequest,this.ProxySettings);
                }

                byte[] data=null;
                if (values!=null)
                {
                    // transform to postdata and encode in bytes
                    string postData = GetPostData(values);
                    data=Encoding.UTF8.GetBytes(postData);
                }

                //httpRequestState.httpRequest.Referer = postUri;

                // set properties
                httpRequestState.HttpRequest.Method="POST";
                httpRequestState.HttpRequest.ContentType="application/x-www-form-urlencoded";
                httpRequestState.HttpRequest.ContentLength=data.Length;

                // get request stream
                Stream stm = httpRequestState.HttpRequest.GetRequestStream();
                stm.Write(data,0,data.Length);
                stm.Close();

                //hwr.ContinueDelegate=getRedirectHeaders;

                // save cookies
                httpRequestState.HttpRequest.CookieContainer=new CookieContainer();
                if ( cookies!=null )
                {
                    httpRequestState.HttpRequest.CookieContainer.Add(cookies);
                }

                HttpWebResponse httpResponse = (HttpWebResponse)httpRequestState.HttpRequest.GetResponse();
                httpRequestState.HttpResponse = httpResponse;

                // get ResponseBuffer
                respBuffer = HttpPipeline.FillResponseBuffer(httpResponse,
                    httpRequestState.HttpRequest,
                    properties,
                    httpRequestState);
            }
            catch (ProtocolViolationException p)
            {
                if ( response!=null )
                {
                    response.Close();
                }
                respBuffer.ErrorMessage = "Protocol Exception:" + p.Message;
                return respBuffer;
            }
            catch (WebException w)
            {
                StringBuilder s = new StringBuilder();
                s.Append("Error message:");
                s.Append(w.Message);
                s.Append("\r\nStatus Code:");
                s.Append(((HttpWebResponse)w.Response).StatusCode);
                s.Append("\r\nStatus Description:");
                s.Append(((HttpWebResponse)w.Response).StatusDescription);

                if ( response!=null )
                {
                    response.Close();
                }
                respBuffer.ErrorMessage = s.ToString();
                return  respBuffer;
            }

            // response here
            return respBuffer;
        }
コード例 #20
0
        /// <summary>
        /// Creates a new Scripting Designer.
        /// </summary>
        public ScriptingDataDesigner()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            objectCount++;

            // Add MainPage UserControl
            mainPage.Dock = DockStyle.Fill;
            mainPage.Visible = false;
            pnUserControl.Controls.Add(mainPage);
            pageIcons.Images.Add(mainPage.Icon);

            // Add Request page
            requestPage.Dock = DockStyle.Fill;
            requestPage.Visible = false;
            pnUserControl.Controls.Add(requestPage);
            pageIcons.Images.Add(requestPage.Icon);

            // Load custom pages.
            ScriptingPageManager pageManager = new ScriptingPageManager();
            BaseScriptingDataPage[] controls = pageManager.LoadDesignerPages("ScriptingDesigner");
            ArrayList loadedPages = new ArrayList();
            foreach ( BaseScriptingDataPage page in controls )
            {
                page.Dock = DockStyle.Fill;
                page.Visible = false;
                pnUserControl.Controls.Add(page);
                loadedPages.Add(page);

                if ( page.Icon == null )
                {
                    throw new ArgumentNullException("Icon","The Icon parameter in BaseScriptingDataPage is null.");
                }
                else
                {
                    pageIcons.Images.Add(page.Icon);
                }
            }

            _loadedPages = (BaseScriptingDataPage[])loadedPages.ToArray(typeof(BaseScriptingDataPage));
            _defaultHttpProperties = (HttpProperties)ConfigManager.Read("greenBlue/httpClient", true);
        }
コード例 #21
0
 /// <summary>
 /// Begins a new asynchronous HTTP Post request. This function is not thread safe.
 /// </summary>
 /// <param name="postUri"> The Url string.</param>
 /// <param name="properties"> The HttpProperties to set for the request.</param>
 /// <param name="values"> The data to post.</param>
 public void StartAsyncHttpPost(string postUri,HttpProperties properties,ArrayList values)
 {
     if ( values != null )
     {
         StartAsyncHttpPost(postUri,properties,values,null);
     }
 }