コード例 #1
0
 public static string Inject(string url, string method, string contenttype, string headers, string body)
 {
     if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(method))
     {
         var guid = Guid.NewGuid().ToString();
         if (!HasPrtl.IsMatch(url))
         {
             url = "http://" + url;
         }
         var uri         = new Uri(url);
         var headerList  = SplitLine.Split(headers).Where(line => !string.IsNullOrWhiteSpace(line)).ToArray();
         var httpheaders = new HTTPRequestHeaders(uri.AbsoluteUri, headerList)
         {
             HTTPMethod = method
         };
         httpheaders["Connection"]       = "keep-alive";
         httpheaders["Calibur-Composer"] = guid;
         httpheaders["Host"]             = uri.Host;
         if (!string.IsNullOrWhiteSpace(contenttype))
         {
             httpheaders["Content-Type"] = contenttype;
         }
         if (!string.IsNullOrWhiteSpace(body))
         {
             httpheaders["Content-Length"] = Encoding.UTF8.GetBytes(body).Length.ToString();
         }
         else
         {
             body = string.Empty;
         }
         var headerstr = httpheaders.ToString(true, true, false);
         FiddlerApplication.oProxy.InjectCustomRequest(headerstr + body);
         return(guid);
     }
     else
     {
         throw new ArgumentException("url or method is empty.");
     }
 }
コード例 #2
0
        public static string InjectRaw(string rawRequest)
        {
            var guid = Guid.NewGuid().ToString();
            var hdbd = SplitHdBd.Split(rawRequest, 2);

            if (hdbd.Length == 2)
            {
                var httpheaders = new HTTPRequestHeaders();
                httpheaders.AssignFromString(hdbd[0]);
                httpheaders["Calibur-Composer"] = guid;
                if (!string.IsNullOrWhiteSpace(hdbd[1]))
                {
                    httpheaders["Content-Length"] = Encoding.UTF8.GetBytes(hdbd[1]).Length.ToString();
                }
                var headerstr = httpheaders.ToString(true, true, false);
                FiddlerApplication.oProxy.InjectCustomRequest(headerstr + hdbd[1]);
                return(guid);
            }
            else
            {
                throw new ArgumentException("Raw request is invalid.");
            }
        }