private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, string sessionId = "") { FlareSolverrRequest req; if (string.IsNullOrWhiteSpace(sessionId)) { sessionId = null; } var url = request.RequestUri.ToString(); FlareSolverrRequestProxy proxy = GetProxy(); if (request.Method == HttpMethod.Get) { req = new FlareSolverrRequestGet { Cmd = "request.get", Url = url, MaxTimeout = MaxTimeout, Proxy = proxy, Session = sessionId }; } else if (request.Method == HttpMethod.Post) { // request.Content.GetType() doesn't work well when encoding != utf-8 var contentMediaType = request.Content.Headers.ContentType?.MediaType.ToLower() ?? "<null>"; if (contentMediaType.Contains("application/x-www-form-urlencoded")) { req = new FlareSolverrRequestPost { Cmd = "request.post", Url = url, PostData = request.Content.ReadAsStringAsync().Result, MaxTimeout = MaxTimeout, Proxy = proxy, Session = sessionId }; } else if (contentMediaType.Contains("multipart/form-data") || contentMediaType.Contains("text/html")) { //TODO Implement - check if we just need to pass the content-type with the relevant headers throw new FlareSolverrException("Unimplemented POST Content-Type: " + contentMediaType); } else { throw new FlareSolverrException("Unsupported POST Content-Type: " + contentMediaType); } } else { throw new FlareSolverrException("Unsupported HttpMethod: " + request.Method); } return(GetSolverRequestContent(req)); }
private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, String sessionID = "") { FlareSolverrRequest req; if (String.IsNullOrWhiteSpace(sessionID)) { sessionID = null; } var url = request.RequestUri.ToString(); FlareSolverrRequestProxy proxy = GetProxy(); if (request.Method == HttpMethod.Get) { req = new FlareSolverrRequestGet { Cmd = "request.get", Url = url, MaxTimeout = MaxTimeout, Proxy = proxy, Session = sessionID }; } else if (request.Method == HttpMethod.Post) { var contentTypeType = request.Content.GetType(); if (contentTypeType == typeof(FormUrlEncodedContent)) { req = new FlareSolverrRequestPost { Cmd = "request.post", Url = url, PostData = request.Content.ReadAsStringAsync().Result, MaxTimeout = MaxTimeout, Proxy = proxy, Session = sessionID }; } else if (contentTypeType == typeof(MultipartFormDataContent)) { //TODO Implement - check if we just need to pass the content-type with the relevant headers throw new FlareSolverrException("Unimplemented POST Content-Type: " + request.Content.Headers.ContentType); } else if (contentTypeType == typeof(StringContent)) { //TODO Implement - check if we just need to pass the content-type with the relevant headers throw new FlareSolverrException("Unimplemented POST Content-Type: " + request.Content.Headers.ContentType); } else { throw new FlareSolverrException("Unsupported POST Content-Type: " + request.Content.Headers.ContentType); } } else { throw new FlareSolverrException("Unsupported HttpMethod: " + request.Method); } return(GetSolverRequestContent(req)); }