© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
27 replies
Turwaith

HttpClient does not return anything

I am currently writing a method that makes a GET request to a server. The code I'm using for that is
using (var httpClient = new HttpClient())
{
    httpClient.Timeout = TimeSpan.FromSeconds(5);
    
    httpClient.DefaultRequestHeaders.Add("licenseKey", licenseKey);
    httpClient.DefaultRequestHeaders.Add("customerKey", customerKey);
    string url = "http://localhost:3001/api/myTool/license/register";
    HttpResponseMessage response = await httpClient.GetAsync(url);
    if (response.IsSuccessStatusCode)
    {
        string responseBody = await response.Content.ReadAsStringAsync();
        JObject json = JObject.Parse(responseBody);
        
        return json["expiresOn"]?.ToString();
    }
    else
    {
        return null;
    }
}
using (var httpClient = new HttpClient())
{
    httpClient.Timeout = TimeSpan.FromSeconds(5);
    
    httpClient.DefaultRequestHeaders.Add("licenseKey", licenseKey);
    httpClient.DefaultRequestHeaders.Add("customerKey", customerKey);
    string url = "http://localhost:3001/api/myTool/license/register";
    HttpResponseMessage response = await httpClient.GetAsync(url);
    if (response.IsSuccessStatusCode)
    {
        string responseBody = await response.Content.ReadAsStringAsync();
        JObject json = JObject.Parse(responseBody);
        
        return json["expiresOn"]?.ToString();
    }
    else
    {
        return null;
    }
}


For the endpoint, I'm currently using Mockoon until the actual server is ready. Now my call does not return. It neither comes back with an actual response nor does it throw the TaskCanceledException which it should after timing out. I've let it run for over 2 minutes now and it never reaches the exception nor the if statement right below the call. How can that happen?
Mockoon logs the call and also seems to send something back, but this never arrives apparently.
I can use call the endpoint successfully using postman, so that can't be it...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ HttpClient does not respect CancellationToken
C#CC# / help
3y ago
✅ Downloading file with HttpClient does not work
C#CC# / help
14mo ago
❔ api doesn't return anything.
C#CC# / help
3y ago
HTTPClient
C#CC# / help
2y ago