My function is below. It works just great with anything up to around 25MB, but greater than that and it stops working. When I say stops working, it throws no exceptions and fails to the noserver result option at the bottom of the function. I can't seem to find any settings referring to any other buffer size though I found some Microsoft Documentation which does say the response buffer is 2GB default.
Any ideas, any help would be appreciated.
- VS2019 ASP.NET
- 4.7.2
Winforms
public async Task<JsonApiResult> GetHttpData(string Message, string serviceMethod) { System.Diagnostics.Debug.Print($"{serviceMethod}{Message}"); HttpClient _httpClient = new HttpClient(); _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/text")); _httpClient.BaseAddress = new Uri(_url); try { ////// StringContent payload = new StringContent(Message, Encoding.UTF8, "application/json"); HttpResponseMessage getResponse = await _httpClient.PostAsync(serviceMethod, payload); if (getResponse.IsSuccessStatusCode) { try { var response = getResponse.Content.ReadAsStringAsync().Result; JsonApiResult result = JsonConvert.DeserializeObject<JsonApiResult>(response); return result; } catch (Exception e) { return new JsonApiResult { Result = "fail", Message = e.Message, Data = "" }; } } else { //<<<<<<<<<<<<<<<<<<<<<<<<< return new JsonApiResult { Result = "fail", Message = getResponse.StatusCode.ToString(), Data = "" }; } } catch (Exception e) { return new JsonApiResult { Result = "errserver", Message = e.Message, Data = "" }; } return new JsonApiResult { Result = "noserver", Message = "Could not connect to server", Data = "" }; }
On the server-side I'm using
public async Task<JsonApiResult> GetMyFileUploads([FromBody]JsonApiResult result)
{
...
GetStreamAsyncto avoid first reading the complete response into memory. Using the stream you can e.g. directly save the incoming data to a file.////it pauses for a while then drops straight thenoserverresult line. None of the exceptions gets triggered. I'm using JSON as I send multiple items of related data at the same time. so I know how to process it on the server. @Robert note I am sending the data to a server. I only want the small response back//<<<<. I get an errorStatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent. It kinda looks like a buffer overrun. Like I said 25MB or more this happens, anything less is fine