Need to develop C# HttpClient PUT request for uploading image. Here is the curl request working well.
curl --location --request PUT 'https://somewheretest.com/abcd/efgh' \
--header 'Content-Type: application/octet-stream' \
--header 'Range: bytes=0-99999' \
--header 'Content-Length: 100000' \
--data-binary '#D:\image.jpg'
I've tried with HttpClient sending request PutAsync with MultipartFormDataContent, gets response Invalid Range. Any suggestion appreciated for the valid way to request uploading image to the server in C# UWP.
I've followed sort of ways. But only CURL is working perfectly. All other's code replies Invalid Range.
1st#
public static async Task<bool> fileUpload(string filePath, long fileSize)
{
string url = "";
try
{
string range = "bytes=0-" + (fileSize - 1).ToString();
using (var client = new System.Net.Http.HttpClient())
{
//client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
//client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/octet-stream");
//client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Length", fileSize.ToString());
//client.DefaultRequestHeaders.TryAddWithoutValidation("Range", range);
Uri uri = new Uri(url);
using (var content = new MultipartFormDataContent())
{
FileStream fs = File.OpenRead(filePath);
var streamContent = new StreamContent(fs);
//HttpContent contents = new StringContent(filePath);
//streamContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream");
//streamContent.Headers.TryAddWithoutValidation("Content-Length", fileSize.ToString());
//streamContent.Headers.TryAddWithoutValidation("Range", range);
//content.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(new StringContent("Content-Type"), "application/octet-stream");
content.Add(new StringContent("Range"), range);
content.Add(new StringContent("Content-Length"), fileSize.ToString());
content.Add(streamContent, "file", Path.GetFileName(filePath));
using (var message = await client.PutAsync(uri, content))
{
var input = await message.Content.ReadAsStringAsync();
//var result = JsonSerializer.Deserialize<FileUploadResult>(input);
Debug.WriteLine($"Response File Upload: {input}");
return true;
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return false;
}
}
2nd#
public static async Task<bool> UploadMultipart(byte[] file, string filename, string url)
{
string contentType = "application/octet-stream";
var webClient = new WebClient();
string boundary = "------------------------" + DateTime.Now.Ticks.ToString("x");
webClient.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
var fileData = webClient.Encoding.GetString(file);
var package = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n{3}\r\n--{0}--\r\n", boundary, filename, contentType, fileData);
var nfile = webClient.Encoding.GetBytes(package);
byte[] resp = webClient.UploadData(url, "PUT", nfile);
return true;
}
3rd#
public static async Task<bool> fileUpload(ValueSet issueToken, string filePath, byte[] fileInByte)
{
int fileSize = fileInByte.Length;
//string range = "bytes=0-" + (fileSize - 1).ToString();
string url = "";
var httpClient = new System.Net.Http.HttpClient();
try
{
//StreamContent streamContent = new StreamContent(new FileStream(filePath, FileMode.Open, FileAccess.Read));
StreamContent streamContent = new StreamContent(new MemoryStream(fileInByte));
streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
streamContent.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, fileSize - 1);
streamContent.Headers.ContentLength = fileSize;
using (var message = await httpClient.PutAsync(url, streamContent))
{
var input = await message.Content.ReadAsStringAsync();
//var result = JsonSerializer.Deserialize<FileUploadResult>(input);
Debug.WriteLine($"Response File Upload: {input}");
return true;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
The only reason for not working, System.Net.Http.HttpClient behaves differently in UWP which I got from wireshark. And another reason server has very old configuration which does not support multipart in the request. Anyway here is my solution with Windows.Web.Http.HttpClient.
public static async Task<bool> fileUpload(ValueSet issueToken, string filePath, byte[] fileInByte)
{
int fileSize = fileInByte.Length;
string range = "bytes=0-" + (fileSize - 1).ToString();
string url = "https://somewheretest.com/abcd/efgh";
var httpClient = new Windows.Web.Http.HttpClient();
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Range", range);
try
{
HttpStreamContent streamContent = new HttpStreamContent(new FileStream(filePath, FileMode.Open, FileAccess.Read));
streamContent.Headers.ContentType = new HttpMediaTypeHeaderValue("application/octet-stream");
using (var message = await httpClient.PutAsync(new Uri(url), streamContent))
{
var output = await message.Content.ToString();
Debug.WriteLine($"Response File Upload: {output}");
return true;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
Related
I am trying to use HttpClient with putasync to send file to server. The function looks like:
public async Task SendCsvFile(string path,string apiKey)
{
try
{
string clientKey = "";
LoggerService.Logger.CreateLog("Log");
LoggerService.Logger.Info("Start:SendCsvFile");
FileStream fileStream = null;
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
HttpClient httpClient = new HttpClient(clientHandler);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Add("x-api-key", clientKey);
string url = "https://test.csv";
var content = new MultipartFormDataContent();
var fileName = Path.GetFileName(path);
fileStream = File.OpenRead(path);
StreamContent streamContent = new StreamContent(fileStream);
content.Add(new StreamContent(fileStream), fileName, fileName);
var response = await httpClient.PutAsync(url, content);
if (response.IsSuccessStatusCode == true)
{
LoggerService.Logger.Info("File sent correctly.");
}
else
{
LoggerService.Logger.Error("Error during sending." + response.StatusCode + ";" + response.ReasonPhrase + ";");
}
fileStream.Close();
LoggerService.Logger.Info("End:SendCsvFile");
}
catch (Exception ex)
{
LoggerService.Logger.Error(ex.ToString());
//return 0;
}
//return 1;
}
File is send fine and it works however Content-disposition header is added to the file to the first line, and client doesn't want that. It's the first time I am doing anything with services and I read through a lot but still I don't know what can i change to not alter the content of csv file.
EDIT.
After I send the file header is added to the content so the file looks like that.
Screenshot from client server
All the data is fine, though the client server processes the data in a way that it should start from column names. So my question really is what can I can change to omit that first line and is it even possible. Maybe thats something obvious but i' m just a newbie in this stuff.
Changing to MultipartContent and Clearing Headers almost work but left me with boundary still visible in a file. Eventually I changed to RestSharp and adding content this way got rid of the problem.
public async Task SendCsvFile(string path, string apiKey)
{
try
{
string clientKey = "";
string url = "";
LoggerService.Logger.CreateLog("CreationAndDispatchStatesWithPrices");
LoggerService.Logger.Info("Start:SendCsvFile");
FileStream fileStream = null;
var fileName = Path.GetFileName(path);
fileStream = File.OpenRead(path);
var client = new RestClient(url);
// client.Timeout = -1;
var request = new RestRequest();
request.AddHeader("x-api-key", clientKey);
request.AddHeader("Content-Type", "text/csv");
request.AddParameter("text/csv", File.ReadAllBytes(path), ParameterType.RequestBody);
RestResponse response = client.Put(request);
if (response.IsSuccessful == true)
{
LoggerService.Logger.Info("File sent correctly.");
}
else
{
LoggerService.Logger.Error("Error sending file." + response.StatusCode + ";" + response.ErrorMessage + ";");
}
fileStream.Close();
LoggerService.Logger.Info("End:SendCsvFile");
}
catch (Exception ex)
{
LoggerService.Logger.Error(ex.ToString());
//return 0;
}
//return 1;
}
The following code works:
string UploadWithHttpRequest(string url, string filePath, string fileName)
{
try
{
byte[] fileByteArray = File.ReadAllBytes(filePath);
string formDataBoundary = $"----------{Guid.NewGuid():N}";
string contentType = "multipart/form-data; boundary=" + formDataBoundary;
byte[] formData = GetMultipartFormDataForUpload(fileByteArray, fileName, contentType, formDataBoundary);
var request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = contentType;
request.UserAgent = Credentials.UserName;
request.CookieContainer = new CookieContainer();
request.ContentLength = formData.Length;
request.Credentials = Credentials;
using (Stream RequestStream = request.GetRequestStream())
{
RequestStream.Write(formData, 0, formData.Length);
RequestStream.Close();
}
var response = request.GetResponse() as HttpWebResponse;
var ResponseReader = new StreamReader(response.GetResponseStream());
string FullResponse = ResponseReader.ReadToEnd();
response.Close();
return FullResponse;
}
catch (Exception ex)
{
throw ex;
}
}
byte[] GetMultipartFormDataForUpload(byte[] byteArray, string fileName, string contentType, string Boundary)
{
Stream FormDataStream = new MemoryStream();
string Header = string.Format("--{0}" + Environment.NewLine + "Content-Disposition: form-data; name=\"{1}\"; filename=\"{2}\""
+ Environment.NewLine + Environment.NewLine, Boundary, "file", fileName);
FormDataStream.Write(Encoding.UTF8.GetBytes(Header), 0, Encoding.UTF8.GetByteCount(Header));
FormDataStream.Write(byteArray, 0, byteArray.Length);
string Footer = Environment.NewLine + "--" + Boundary + "--" + Environment.NewLine;
FormDataStream.Write(Encoding.UTF8.GetBytes(Footer), 0, Encoding.UTF8.GetByteCount(Footer));
FormDataStream.Position = 0L;
var FormData = new byte[(int)(FormDataStream.Length - 1L + 1)];
FormDataStream.Read(FormData, 0, FormData.Length);
FormDataStream.Close();
return FormData;
}
But instead of using HttpRequest I'd like to use HttpClient and instead of doing all the encoding manually (especially in GetMultipartFormDataForUpload) I'd like to use the class MultipartFormDataContent. When I try this, I always get a 500 from the server. This is what I have tried so far:
async Task<string> UploadWithHttpClient(string url, string filePath, string fileName)
{
try
{
byte[] fileByteArray = File.ReadAllBytes(filePath);
var content = new MultipartFormDataContent("------------" + Guid.NewGuid());
var byteArrayContent = new ByteArrayContent(fileByteArray, 0, fileByteArray.Length);
//Option 1
byteArrayContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = fileName
};
//Option 2
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = fileName
};
content.Add(byteArrayContent, "file");
var client = new HttpClient();
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
return result;
}
catch (Exception ex)
{
throw ex;
}
}
What is the right way to replace the httprequest with the httpclient?
Where does the content-disposition header belong (is one of the options I have tried correct)? If yes what else is my problem?
the following code worked for me in the end:
async Task<string> UploadWithHttpClient(string url, string filePath, string fileName)
{
try
{
byte[] fileByteArray = File.ReadAllBytes(filePath);
var content = new MultipartFormDataContent("------------" + Guid.NewGuid());
var byteArrayContent = new ByteArrayContent(fileByteArray);
byteArrayContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf");
content.Add(byteArrayContent, "\"file\"", $"\"{fileName}\"");
var client = new HttpClient();
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
return result;
}
catch (Exception ex)
{
throw ex;
}
}
```
I have an API using POST Method.From this API I can download the file via Postmen tool.But I would like to know how to download file from C# Code.I have tried below code but POST Method is not allowed to download the file.
Code:-
using (var client = new WebClient())
{
client.Headers.Add("X-Cleartax-Auth-Token", ConfigurationManager.AppSettings["auth-token"]);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
string url = ConfigurationManager.AppSettings["host"] + ConfigurationManager.AppSettings["taxable_entities"] + "/ewaybill/download?print_type=detailed";
TransId Id = new TransId()
{
id = TblHeader.Rows[0]["id"].ToString()
};
List<string> ids = new List<string>();
ids.Add(TblHeader.Rows[0]["id"].ToString());
string DATA = JsonConvert.SerializeObject(ids, Newtonsoft.Json.Formatting.Indented);
string res = client.UploadString(url, "POST",DATA);
client.DownloadFile(url, ConfigurationManager.AppSettings["InvoicePath"].ToString() + CboGatePassNo.EditValue.ToString().Replace("/", "-") + ".pdf");
}
Postmen Tool:-
URL : https://ewbbackend-preprodpub-http.internal.cleartax.co/gst/v0.1/taxable_entities/1c74ddd2-6383-4f4b-a7a5-007ddd08f9ea/ewaybill/download?print_type=detailed
Header :-
Content-Type : application/json
X-Cleartax-Auth-Token :b1f57327-96db-4829-97cf-2f3a59a3a548
Body :-
[
"GLD24449"
]
using (WebClient client = new WebClient())
{
client.Headers.Add("X-Cleartax-Auth-Token", ConfigurationManager.AppSettings["auth-token"]);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
string url = ConfigurationManager.AppSettings["host"] + ConfigurationManager.AppSettings["taxable_entities"] + "/ewaybill/download?print_type=detailed";
client.Encoding = Encoding.UTF8;
//var data = "[\"GLD24449\"]";
var data = UTF8Encoding.UTF8.GetBytes(TblHeader.Rows[0]["id"].ToString());
byte[] r = client.UploadData(url, data);
using (var stream = System.IO.File.Create("FilePath"))
{
stream.Write(r,0,r.length);
}
}
Try this. Remember to change the filepath. Since the data you posted is not valid
json. So, I decide to post data this way.
I think it's straight forward, but instead of using WebClient, you can use HttpClient, it's better.
here is the answer HTTP client for downloading -> Download file with WebClient or HttpClient?
comparison between the HTTP client and web client-> Deciding between HttpClient and WebClient
Example Using WebClient
public static void Main(string[] args)
{
string path = #"download.pdf";
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
var uri = new Uri("https://ewbbackend-preprodpub-http.internal.cleartax.co/gst/v0.1/taxable_entities/1c74ddd2-6383-4f4b-a7a5-007ddd08f9ea/ewaybill/download?print_type=detailed");
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.Headers.Add("X-Cleartax-Auth-Token", "b1f57327-96db-4829-97cf-2f3a59a3a548");
client.Encoding = Encoding.UTF8;
var data = UTF8Encoding.UTF8.GetBytes("[\"GLD24449\"]");
byte[] r = client.UploadData(uri, data);
using (var stream = System.IO.File.Create(path))
{
stream.Write(r, 0, r.Length);
}
}
Here is the sample code, don't forget to change the path.
public class Program
{
public static async Task Main(string[] args)
{
string path = #"download.pdf";
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
var uri = new Uri("https://ewbbackend-preprodpub-http.internal.cleartax.co/gst/v0.1/taxable_entities/1c74ddd2-6383-4f4b-a7a5-007ddd08f9ea/ewaybill/download?print_type=detailed");
HttpClient client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, uri)
{
Content = new StringContent("[\"GLD24449\"]", Encoding.UTF8, "application/json")
};
request.Headers.Add("X-Cleartax-Auth-Token", "b1f57327-96db-4829-97cf-2f3a59a3a548");
var response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
using (FileStream fs = File.Create(path))
{
await response.Content.CopyToAsync(fs);
}
}
else
{
}
}
I am trying to post one or more files from my local machine to an API with HttpClient, MultipartFormContent and ContentType: "application/octet-stream" but when i do postSync and call an API from a local Winform application, the result of the task (var response = task.Result;) says that it is "Unsopported Type File" StatusCode: 415. I tried with ByteArrayContent but was still unsuccessful.
This is my code:
bool Upload(string url, string path, string localFilename, string fileName, string projectId, string folderId)
{
Boolean isFileUploaded = false;
string xapiKey = "-----";
try
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(url);
httpClient.DefaultRequestHeaders.Add("x-api-key", xapiKey);
var fileInfo = new FileInfo(localFilename);
FileUpload uploadResult = null;
bool _fileUploaded = false;
//Extract content file
FileStream fileStream = File.OpenRead(path);
var streamContent = new StreamContent(fileStream);
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
streamContent.Headers.ContentDisposition.FileName = "\"" + Path.GetFileName(path) + "\"";
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octetstream");
string boundary = Guid.NewGuid().ToString();
MultipartFormDataContent content = new MultipartFormDataContent(boundary);
content.Headers.Remove("Content-Type");
content.Headers.TryAddWithoutValidation("Content-Type", "mulitpart/form-data; boundary=" + boundary);
content.Add(streamContent);
//content.Add(new StreamContent(fileStream), "\"file\"", string.Format("\"{0}\"", fileName + fileInfo.Extension));
Task taskUpload = httpClient.PostAsync(url, content).ContinueWith(task =>
{
if (task.Status == TaskStatus.RanToCompletion)
{
var response = task.Result;
if (response.IsSuccessStatusCode)
{
uploadResult = response.Content.ReadAsAsync<FileUpload>().Result;
if (uploadResult != null)
_fileUploaded = true;
}
}
fileStream.Dispose();
});
taskUpload.Wait();
if (_fileUploaded)
isFileUploaded = true;
httpClient.Dispose();
}
catch (Exception ex)
{
isFileUploaded = false;
throw new Exception(ex.Message);
}
return isFileUploaded;
}
I'm trying to upload an image with a POST request with an API call.
Getting the image from the gallery works. By using:
StartActivityForResult(
Intent.CreateChooser(imageIntent, "Select photo"), 0);
With that, I receive an intent with different paths like:
EncodedSchemeSpecificPart,
EncodedPath,
Path, etc.
I've tested the API call with POSTMAN, as form-data that has a file with the keyname file and also an auth-token inside the header. This works.
Now my question is, how do I add a file(image) in a POST call with C#?
This is what I have so far:
try
{
Uri url = new Uri(basePath + "/pictures");
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(url);
request.ContentType = "application/json";
request.Method = "POST";
request.Headers.Add("auth-token", accesstoken);
return null;
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
return null;
}
edit: the backend code:
#POST
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(#HeaderParam("Auth-Token") String token,
#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataBodyPart body) throws RequestException {
secure(token, "*");
// Get the user data using the entity manager
String subtype = body.getMediaType().getSubtype();
switch(subtype) {
case "jpeg":
case "jpg":
case "png":
break;
default:
return Response.status(Response.Status.BAD_REQUEST).build();
}
String imageName = UUID.randomUUID().toString() + "." + subtype;
String uploadedFileLocation = context.getRealPath("/images/"+imageName);
Picture picture = pictureService.createPictureReference(uploadedFileLocation);
// Store the file
try {
writeToFile(uploadedInputStream, uploadedFileLocation);
// If the file is stored
return Response.status(Response.Status.OK).entity(picture).build();
} catch (IOException e){
e.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
You can StartActivityForResult using an intent that returns the chosen image so you can obtain a stream from
StartActivityForResult (Image picker/gallery)
using (var intent = new Intent())
{
intent.SetType("image/*");
intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(intent, "Select Image To Upload"), PickImage);
}
Now in your OnActivityResult you can use the ContentResolver to obtain a stream from the picked image that you can Post as binary (octet-stream) or convert it to base64 (application/json) to match your MultipartFormDataContent API/Post requirements.
Note: Using Jersey?, as I am not sure how to interpret the InputStream vs FormDataBodyPart params when using json, is the InputStream in base64?
OnActivityResult and HttpClient Post w/ StreamContent
const string url = "http://10.0.2.2:5000/api/image";
AndroidClientHandler handler;
HttpClient client;
protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
string access_token = "some oauth2 token";
if (resultCode.HasFlag(Result.Ok) && requestCode == PickImage)
{
using (var imageStream = ContentResolver.OpenInputStream(data.Data))
{
await Task.Run(async () =>
{
handler = handler ?? new AndroidClientHandler();
client = client ?? new HttpClient(handler);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth2", access_token);
if (!client.DefaultRequestHeaders.Contains("Accept"))
{
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
client.Timeout = TimeSpan.FromSeconds(30);
}
using (var content = new StreamContent(imageStream))
using (var response = await client.PostAsync(url, content))
{
Log.Debug(TAG, $"Post: {response.StatusCode} : {response.IsSuccessStatusCode}");
}
}).ContinueWith((task) =>
{
Log.Debug(TAG, $"Post: {task.Status}");
if (task.IsFaulted)
{
Log.Debug(TAG, $"Post Faulted: {task.Exception.Message}");
Log.Debug(TAG, $"Post Faulted: {task.Exception?.InnerException.Message}");
}
});
}
}
}
Update:
Based upon needing to post something like this:
POST /pictures HTTP/1.1
Host: 127.0.0.1:60000
auth-token: some_token_here
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="foobar.png"
Content-Type: image/png
------WebKitFormBoundary7MA4YWxkTrZu0gW--
MultipartFormDataContent with image content:
await Task.Run(async () =>
{
handler = handler ?? new AndroidClientHandler();
client = client ?? new HttpClient(handler);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("auth-token", access_token);
using (var imageStream = ContentResolver.OpenInputStream(data.Data))
using (var streamContent = new StreamContent(imageStream))
using (var byteArrayContent = new ByteArrayContent(await streamContent.ReadAsByteArrayAsync()))
using (var formDataContent = new MultipartFormDataContent())
{
formDataContent.Add(byteArrayContent, "file", "DummyFileName.NotUsedOnServer");
foreach (var content in formDataContent)
{
content.Headers.ContentType = new MediaTypeHeaderValue(ContentResolver.GetType(data.Data));
break;
}
using (var response = await client.PostAsync(url, formDataContent))
{
Log.Debug(TAG, $"Post: {response.StatusCode} : {response.IsSuccessStatusCode}");
}
}
}).ContinueWith((task) =>
{
Log.Debug(TAG, $"Post: {task.Status}");
if (task.IsFaulted)
{
Log.Error(TAG, $"Post Faulted: {task.Exception.Message}");
Log.Error(TAG, $"Post Faulted: {task.Exception?.InnerException.Message}");
}
});