示例#1
0
 private string InjectionParam(string v)
 {
     if (v == null)
     {
         return(v);
     }
     foreach (var p in Parameters)
     {
         if (v.IndexOf("{" + p.Key + "}") >= 0)
         {
             Log.Log($"Parameter Substitution: parameter \"{p.Key}\" = \"{p.Value}\"");
             v = v.Replace("{" + p.Key + "}", p.Value);
         }
     }
     return(v);
 }
示例#2
0
 public void web_add_auto_header(string name, string value)
 {
     functionCore.web_add_auto_header(name, value);
     Log.Log($"web_add_auto_header({name}) was successful");
 }
示例#3
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            HttpResponseMessage response;
            uint redirectCount = 0;

            while (true)
            {
                var cookieHeader = cookieContainer.GetCookieHeader(request.RequestUri);
                response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

                _log.Network(response, cookieHeader);

                if (!RequestNeedsRedirect(response))
                {
                    break;
                }

                Uri location = response.Headers.Location;
                if (location == null)
                {
                    throw new HttpRequestException("location not found");
                }

                if (!location.IsAbsoluteUri)
                {
                    location = new Uri(request.RequestUri, location);
                }

                // Disallow automatic redirection from https to http
                bool allowed =
                    (request.RequestUri.Scheme == "http" && (location.Scheme == "http" || location.Scheme == "https")) ||
                    (request.RequestUri.Scheme == "https" && location.Scheme == "https");
                if (!allowed)
                {
                    break;
                }

                redirectCount++;
                if (redirectCount > _maxAutomaticRedirections)
                {
                    throw new HttpRequestException(" redirectCount Exceed maximum : " + _maxAutomaticRedirections);
                }
                _log.Log($"Redirecting \"{request.RequestUri}\" (redirection depth is {redirectCount-1})");



                // Set up for the automatic redirect
                request.RequestUri = location;

                //creatNewRequest
                //var lastRequest = request;
                //request = new HttpRequestMessage(lastRequest.Method, location);
                //request.Content = lastRequest.Content;
                //foreach (var h in lastRequest.Headers) {
                //    request.Headers.Add(h.Key, h.Value);
                //}


                _log.Log($"To location \"{request.RequestUri}\"");

                if (RequestRequiresForceGet(response.StatusCode, request.Method))
                {
                    request.Method  = HttpMethod.Get;
                    request.Content = null;
                }

                // Do the redirect.
                response.Dispose();
            }

            return(response);
        }