ho questo metodo, puoi aggiungere la gestione del codice dell'errore? " string url =…
- User
ho questo metodo, puoi aggiungere la gestione del codice dell'errore? " string url = Endpoint + "Archival/api/v1/migration/aoos/" + AooId + "/archival-packages/" + ArchivalPackageId + "/documents"; using (var httpClient = new HttpClient()) { try { // Imposta le intestazioni httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("/")); httpClient.DefaultRequestHeaders.Add("X-Authorization", IXCeAccessToken);
code// Crea il contenuto della richiesta using (var form = new MultipartFormDataContent()) { // Aggiungi il file //var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)); //fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); //form.Add(fileContent, "DocumentFile ", Path.GetFileName(filePath)); form.Add(new StreamContent(File.OpenRead(filePath)) { Headers = { ContentType = new MediaTypeHeaderValue("application/pkcs7-mime") } }, "DocumentFile", Path.GetFileName(filePath)); // Aggiungi altri campi form.Add(new StringContent(PreservationDocTypeUID.ToString()), "PreservationDocTypeUID"); form.Add(new StringContent(fileSincroId), "FileSincroID"); form.Add(new StringContent(hash), "SHA256FileHash"); string metadatajson = JsonConvert.SerializeObject(metadata); form.Add(new StringContent(metadatajson, Encoding.UTF8, "application/json"), "metadata"); // Invia la richiesta var response = httpClient.PostAsync(url, form).Result; // Sincrono Logger.Logger.Instance.Info("Risultato chiamata documenti" + Newtonsoft.Json.JsonConvert.SerializeObject(response)); response.EnsureSuccessStatusCode(); } } catch (HttpRequestException e) { throw new Exception("Errore nella richiesta HTTP: " + e.Message); } catch (Exception e) { throw new Exception("Si è verificato un errore: " + e.Message); } - Assistant