public void HttpBuilder_Test() { var httpBuilder = new HttpBuilder("/user", Method.GET, DataFormat.None); httpBuilder.Parameters = new List <Parameter>() { new Parameter("px", "px", ParameterType.UrlSegment) }; httpBuilder.AddParameter(new Parameter("p1", "v1", ParameterType.HttpHeader)); httpBuilder.AddParameter("p2", 22); httpBuilder.AddParameter("p3", 33m, ParameterType.QueryString); httpBuilder.AddFile("f1", "DotCommon.dll", "f1/contentType"); httpBuilder.AddFile("f2", new byte[] { 1 }, "f2.txt", "f2/contentType"); httpBuilder.AddFile("f3", w => { }, "f3.txt", 1, "f3/contentType"); httpBuilder.AddFile(new FileParameter() { Name = "f4", FileName = "f4.txt", ContentLength = 101, ContentType = "f4/contentType", }); Assert.Contains(httpBuilder.Parameters, x => x.Name == "p1"); Assert.Equal(Method.GET, httpBuilder.Method); Assert.Equal("/user", httpBuilder.Resource); Assert.Equal(4, httpBuilder.Files.Count); Assert.Equal(4, httpBuilder.Parameters.Count); Assert.Equal(DataFormat.None, httpBuilder.DataFormat); }
/// <summary>创建HttpBuilder /// </summary> public override HttpBuilder CreateBuilder() { var builder = new HttpBuilder("/submit", Method.POST); if (!FilePath.IsNullOrWhiteSpace()) { builder.AddFile("file", FilePath); } if (FileBytes != null && FileBytes.Length > 0) { builder.AddFile("file", FileBytes, FileName); } if (Writer != null) { builder.AddFile("file", Writer, FileName, ContentLength.Value); } return(builder); }