C
C#2y ago
khamas

❔ httpclient not sending request and no exception is thrown

hey I have an httpclient post request that is just hanging there, no exception thrown or anything, I
15 Replies
khamas
khamasOP2y ago
I tried to set a timeout, and set a breakpoint at the server API level, but none hit
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
in the init
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
private static HttpClient _httpClient = new HttpClient() { Timeout = TimeSpan.FromSeconds(10) }; the thing is, my solution is running 5 projects in parallel, all the projects using this shared query method work fine it's only in 1 project that it doesn't work, which is a blazor server project
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
private static HttpClient _httpClient = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(10)
};
public static async Task<HttpResponseMessage> CallAsync(string path, Dictionary<string, string> form = null)
{
//_httpClient.Timeout = TimeSpan.FromSeconds(10);
try
{
if (form is null) form = new Dictionary<string, string>();
using var content = new FormUrlEncodedContent(form);

using var req = new HttpRequestMessage(HttpMethod.Post, new Uri($"{Ez.SharedStoreUrl}{path}"))
{
Content = content,
};

var resp = await _httpClient.SendAsync(req);
return resp;

//return await _httpClient.PostAsync(Ez.SharedStoreUrl + path, content);
}
catch (Exception e)
{
Console.WriteLine($"POST ERROR: {e}");

using var content = new StringContent("Server offline");
return new HttpResponseMessage()
{
StatusCode = HttpStatusCode.RequestTimeout,
Content = content,
};
}
}
private static HttpClient _httpClient = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(10)
};
public static async Task<HttpResponseMessage> CallAsync(string path, Dictionary<string, string> form = null)
{
//_httpClient.Timeout = TimeSpan.FromSeconds(10);
try
{
if (form is null) form = new Dictionary<string, string>();
using var content = new FormUrlEncodedContent(form);

using var req = new HttpRequestMessage(HttpMethod.Post, new Uri($"{Ez.SharedStoreUrl}{path}"))
{
Content = content,
};

var resp = await _httpClient.SendAsync(req);
return resp;

//return await _httpClient.PostAsync(Ez.SharedStoreUrl + path, content);
}
catch (Exception e)
{
Console.WriteLine($"POST ERROR: {e}");

using var content = new StringContent("Server offline");
return new HttpResponseMessage()
{
StatusCode = HttpStatusCode.RequestTimeout,
Content = content,
};
}
}
how do I check that?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
khamas
khamasOP2y ago
these are the only packages I see
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
but the method from which I call the client is in a shared project all are net6
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamasOP2y ago
that's very complicated is there any way to catch the problem? @jgallant
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server