public override ActionBase CreateFromForm()
        {
            var action = new HttpPostAction
            {
                HttpMethod                 = this.ddlHttpMethod.SelectedValue,
                Url                        = this.txtUrl.Text,
                LogResponseBody            = this.chkLogResponseBody.Checked,
                SaveResponseBodyAsVariable = this.chkSaveResponseBodyInVariable.Checked,
                ErrorStatusCodes           = StatusCodeRangeList.Parse(this.txtErrorStatusCodes.Text).ToString(),
                LogRequestData             = this.chkLogContent.Checked
            };

            if (this.chkRawInput.Checked)
            {
                action.PostData    = this.txtBody.Text;
                action.ContentType = AH.NullIf(this.txtContentType.Text, string.Empty);
            }
            else
            {
                action.FormData = (from f in this.ctlFormData.Value.Split('&')
                                   where !string.IsNullOrEmpty(f)
                                   let p = f.Split(new[] { '=' }, 2)
                                           where p.Length == 2
                                           let k = Uri.UnescapeDataString(p[0]).Trim()
                                                   let v = Uri.UnescapeDataString(p[1]).Trim()
                                                           where !string.IsNullOrEmpty(k)
                                                           select new KeyValuePair <string, string>(k, v)).ToList();
            }

            return(action);
        }
 public override ActionBase CreateFromForm()
 {
     return(new HttpGetAction
     {
         HttpMethod = this.ddlHttpMethod.SelectedValue,
         Url = this.txtUrl.Text,
         LogResponseBody = this.chkLogResponseBody.Checked,
         SaveResponseBodyAsVariable = this.chkSaveResponseBodyInVariable.Checked,
         ErrorStatusCodes = StatusCodeRangeList.Parse(this.txtErrorStatusCodes.Text).ToString(),
     });
 }
예제 #3
0
        protected void ProcessResponse(HttpWebResponse response)
        {
            string message = string.Format("Server responded with status code {0} - {1}.", (int)response.StatusCode, Util.CoalesceStr(response.StatusDescription, response.StatusCode));

            var errorCodeRanges = StatusCodeRangeList.Parse(this.ErrorStatusCodes);

            if (errorCodeRanges.IsInAnyRange((int)response.StatusCode))
            {
                this.LogError(message);
            }
            else
            {
                this.LogInformation(message);
            }

            if (this.LogResponseBody || this.SaveResponseBodyAsVariable)
            {
                if (response.ContentLength == 0)
                {
                    this.LogDebug("The Content Length of the response was 0.");
                    return;
                }

                try
                {
                    string text = new StreamReader(response.GetResponseStream()).ReadToEnd();

                    if (this.SaveResponseBodyAsVariable)
                    {
                        this.LogDebug("Saving response body to ${0} variable...", HttpActionBase.HttpResponseBodyVariableName);
                        this.Context.Variables[HttpActionBase.HttpResponseBodyVariableName] = text;
                    }

                    if (this.LogResponseBody)
                    {
                        if (text.Length > MaxResponseLength)
                        {
                            text = text.Substring(0, MaxResponseLength);
                            this.LogDebug("The following response Content Body is truncated to {0} characters...", MaxResponseLength);
                        }

                        if (!string.IsNullOrEmpty(text))
                        {
                            this.LogInformation("Response Content Body: {0}", text);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.LogWarning("Could not read response Content Body because: {0}", ex.Message);
                }
            }
        }