Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# HttpClient just stops without any indication why

Tags:

I am trying to fetch data from our API instance. The code I have is pretty much copied MS website with teaks found on SO. The code that I am using is this:

string peopleEndpoint = $"{apiConf.ApiEndpoint}/{apiConf.dbspec}/_table/mdm.PEOPLE_SV";
string json = null;
try
{
    using (var httpClient = new HttpClient())
    {
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiConf.ApiKey);
        HttpResponseMessage response = await httpClient.GetAsync(peopleEndpoint);
        json = await response.Content.ReadAsStringAsync();
    }
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
    throw;
}

The configuration values are good... I can copy them and paste them into a cURL command and get the data. Same with the headers.

Now when I debug, execution stops after executing this line:

HttpResponseMessage response = await httpClient.GetAsync(peopleEndpoint);

And, in the output window, all I see is:

The program '[10172] dotnet.exe' has exited with code 0 (0x0).
The program '[10172] dotnet.exe: Program Trace' has exited with code 0 (0x0).

How can I figure out what is causing this failure?

The framework is noted as:

<TargetFramework>netcoreapp2.1</TargetFramework>
like image 623
Eric Avatar asked Nov 05 '18 16:11

Eric


People also ask

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


1 Answers

Is the code async all the way to the top or is there a non async method that calls this code somewhere that may not be waiting until it is complete. That's kind of what this smells like to me.

like image 142
Matti Price Avatar answered Nov 30 '22 04:11

Matti Price