public void RegisterEndpointHandler(string pathMatch, HttpConsumer handler) { if (_started) { throw new InvalidOperationException("The host has already been started, no additional endpoints may be added."); } if (_log.IsDebugEnabled) { _log.DebugFormat("Adding Endpoint Handler: {0}", pathMatch); } lock (_endpoints) { if (_endpoints.TryGetValue(pathMatch, out List <Endpoint> handlers)) { handlers.Add(new Endpoint(pathMatch, handler)); } else { _endpoints.Add(pathMatch, new List <Endpoint> { new Endpoint(pathMatch, handler) }); } } }
static void Main(string[] args) { IHttpConsumer httpConsumer = new HttpConsumer(); var val = httpConsumer .Host("http://localhost:1977/api/") .AddDeserializer(new NewtoneJsonSerialize()) // .AddSerializer(new NewtoneJsonSerialize()) .Resource("BasicAuth/", x => x.SetContentType(ContentType.Json)) .Get <User>() .BuildAsync() .GetAwaiter() .GetResult(); //var val = httpConsumer // .Host("http://localhost:1977/api/") // .AddDeserializer(new NewtoneJsonSerialize()) // // .AddSerializer(new NewtoneJsonSerialize()) // .Resource("values/v/", x => x.SetContentType(ContentType.Json)) // .Get<User>() // .Next("values/d/") // .Get<User>() // .Aggregate<AgUser>((x, y) => // { // x.Get<User>(0, y) // .Bind(x => x.Name1, z => z.Name1) // .Get<User>(1, y) // .Bind(x => x.Name1, z => z.Name); // }) // .BuildAsync() // .GetAwaiter() // .GetResult(); Console.WriteLine($"Hello World!"); }
/// <summary> /// Initializes a new instance of the Mooc request class with cookies and the specified url. /// </summary> /// <param name="cookies">cookies of icourse163.org.</param> /// <param name="courseUrl">url of the course.</param> public MoocRequest(IReadOnlyCollection <CookieModel> cookies, string courseUrl) { _consumer = HttpConsumer.Create(); _courseId = GetCourseId(courseUrl); _cookies = new CookieCollection(); foreach (var cookie in cookies) { _cookies.Add(new Cookie(cookie.Name, cookie.Value)); } _sessionId = cookies.FirstOrDefault(c => c.Name == "NTESSTUDYSI")?.Value ?? string.Empty; }
void HttpHostContext.RegisterEndpointHandler(string pathMatch, HttpConsumer handler) { _context.RegisterEndpointHandler(pathMatch, handler); }
public Endpoint(string pathMatch, HttpConsumer handler) { PathMatch = pathMatch; Handler = handler; }