We are getting 502 error when we try to send photo in Json. App developed with .NET and Xamarin.Form
var jsonObjGuid = JsonConvert.SerializeObject(ObjGuid);
var jsonObjFiles = JsonConvert.SerializeObject(ObjFiles, Formatting.Indented);
var url = $"{ Session.EndpointURL}{MethodNames.UploadDossierFiles.Value}";
try
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.TransferEncodingChunked = true;
httpClient.Timeout = TimeSpan.FromMilliseconds(600000);
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url))
{
//request.Headers.Add(HeaderKeys.UserAgent.Value, Resources.DefaultUserAgent);
request.Headers.Add(HeaderKeys.UserAgent.Value, "MobileApp");
request.Headers.Add(HeaderKeys.Token.Value, token);
HttpContent ObjGuidContent = new StringContent(jsonObjGuid);
HttpContent ObjFilesContent = new StringContent(jsonObjFiles);
MultipartFormDataContent content = new MultipartFormDataContent
{
{ObjGuidContent, "ObjGuid"},
{ObjFilesContent, "ObjFiles"}
};
request.Content = content;
var response = await Policy.HandleResult<HttpResponseMessage>(message => !message.IsSuccessStatusCode)
.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(2), (result, timeSpan, retryCount, context) => { })
.ExecuteAsync(() => httpClient.SendAsync(request));
}
}
}
Sometimes it works but often I get this error. Any help, suggestions? What do I need to check?