Exemplo n.º 1
0
        private HttpRequestMessage CreateRequest(HttpMethod method, string path, Action <BrowserContext> browserContext)
        {
            var context =
                new BrowserContext();



            this.SetCookies(context);

            browserContext.Invoke(context);

            var contextValues =
                (IBrowserContextValues)context;

            BuildRequestBody(contextValues);

            //var requestStream =
            //    RequestStream.FromStream(contextValues.Body, 0, true);

            var request = new HttpRequestMessage();

            request.Method     = method;
            request.RequestUri = new Uri(contextValues.Protocol + "://" + contextValues.UserHostAddress + path + contextValues.QueryString);

            request.Content = new StreamContent(contextValues.Body);

            foreach (var header in contextValues.Headers)
            {
                if (header.Key.StartsWith("Content") && !request.Content.Headers.Contains(header.Key))
                {
                    request.Content.Headers.Add(header.Key, header.Value);
                }
                else if (!header.Key.StartsWith("Content") && !request.Headers.Contains(header.Key))
                {
                    request.Headers.Add(header.Key, header.Value);
                }
            }

            return(request);
        }
Exemplo n.º 2
0
 private void DefaultBrowserContext(BrowserContext context)
 {
     context.HttpRequest();
 }
 /// <summary>
 /// Adds a multipart/form-data encoded request body to the <see cref="Browser"/>, using the default boundary name.
 /// </summary>
 /// <param name="browserContext">The <see cref="BrowserContext"/> that the data should be added to.</param>
 /// <param name="multipartFormData">The multipart/form-data encoded data that should be added.</param>
 public static void MultiPartFormData(this BrowserContext browserContext, BrowserContextMultipartFormData multipartFormData)
 {
     MultiPartFormData(browserContext, multipartFormData, BrowserContextMultipartFormData.DefaultBoundaryName);
 }
 /// <summary>
 /// Adds a header to indicate this request is an "ajax request"
 /// <seealso cref="RequestExtensions.IsAjaxRequest"/>
 /// </summary>
 /// <param name="browserContext">The <see cref="BrowserContext"/> that the data should be added to.</param>
 public static void AjaxRequest(this BrowserContext browserContext)
 {
     browserContext.Header("X-Requested-With", "XMLHttpRequest");
 }
Exemplo n.º 5
0
        private HttpRequestMessage CreateRequest(HttpMethod method, string path, Action<BrowserContext> browserContext)
        {
            var context =
                new BrowserContext();

            

            this.SetCookies(context);

            browserContext.Invoke(context);

            var contextValues =
                (IBrowserContextValues)context;

            BuildRequestBody(contextValues);

            //var requestStream =
            //    RequestStream.FromStream(contextValues.Body, 0, true);

            var request = new HttpRequestMessage();
            request.Method = method;
            request.RequestUri = new Uri(contextValues.Protocol + "://" + contextValues.UserHostAddress + path + contextValues.QueryString);

            request.Content = new StreamContent(contextValues.Body);

            foreach (var header in contextValues.Headers)
            {

                if (header.Key.StartsWith("Content") && !request.Content.Headers.Contains(header.Key))
                {
                    request.Content.Headers.Add(header.Key, header.Value);
                }
                else if (!header.Key.StartsWith("Content") && !request.Headers.Contains(header.Key))
                {
                    request.Headers.Add(header.Key, header.Value);
                }
            }

            return request;
        }
Exemplo n.º 6
0
        private void SetCookies(BrowserContext context)
        {
            if (!this.cookies.Any())
            {
                return;
            }

            var cookieString = this.cookies.Aggregate(string.Empty, (current, cookie) => current + string.Format("{0}={1};", HttpUtility.UrlEncode(cookie.Key), HttpUtility.UrlEncode(cookie.Value)));

            context.Header("Cookie", cookieString);
        }
Exemplo n.º 7
0
 private void DefaultBrowserContext(BrowserContext context)
 {
     context.HttpRequest();
 }