private FileScan CreateFileScan(ResponseAPI responseAPI) { if (responseAPI is null) { return(null); } if (responseAPI.StatusCode == HttpStatusCode.OK) { return(JsonConvert.DeserializeObject <FileScan>(responseAPI.Result)); } else { return(null); } }
public FileScan FileReport(string resource) { this.ApiParams = new string[] { "report" }; Dictionary <string, string> ApiParams = new Dictionary <string, string>() { ["apikey"] = ApiKey, ["resource"] = resource }; string URL = GetFullAPIURL(ApiParams); ResponseAPI responseAPI = RequestAPI.SendRequest(URL, Method.GET).Result; return(CreateFileScan(responseAPI)); }
public FileScan FileScan(PostFile file) { this.ApiParams = new string[] { "scan" }; string URL = GetFullAPIURL(); Dictionary <string, object> ApiParams = new Dictionary <string, object>() { ["file"] = file, ["apikey"] = ApiKey }; ResponseAPI responseAPI = RequestAPI.SendRequest(URL, Method.POST, ApiParams).Result; return(CreateFileScan(responseAPI)); }
private UrlScan CreateUrlScan(ResponseAPI responseAPI) { if (responseAPI is null) { return(null); } if (responseAPI.StatusCode == HttpStatusCode.OK) { //Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); return(JsonConvert.DeserializeObject <UrlScan>(responseAPI.Result)); } else { return(null); } }
public static async Task <ResponseAPI> SendRequest(string URL, Method method, Dictionary <string, object> RequestBodies = null) { try { ResponseAPI response = new ResponseAPI(); if (method == Method.GET) { using (HttpClient httpClient = new HttpClient()) { httpClient.Timeout = TimeOut; HttpResponseMessage httpresponse = await httpClient.GetAsync(URL); httpresponse.EnsureSuccessStatusCode(); response.Result = httpresponse.Content.ReadAsStringAsync().Result; response.StatusCode = httpresponse.StatusCode; } } else if (method == Method.POST) { using (HttpClient httpClient = new HttpClient()) { httpClient.Timeout = TimeOut; HttpResponseMessage httpresponse = await httpClient.PostAsync(URL, CreateMultiPartBodies(RequestBodies)); httpresponse.EnsureSuccessStatusCode(); httpClient.Dispose(); response.Result = httpresponse.Content.ReadAsStringAsync().Result; response.StatusCode = httpresponse.StatusCode; } } return(response); } catch { return(null); } }