✅ How to talk to Web API hosted on RPI?

Hello, I have created a Web API project with C# and I have published that project to my Pi. When I run the 'launch' command on my Pi I receive:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
In Postman, I want to connect to it by using the following http://{my-PI-IP}:5000/{my-Endpoint} Yet I keep receiving Error: connect ECONNREFUSED {my-PI-IP}:5000. The image describes my publish specifications. And In my program.cs I only added these lines of code just to be sure: Program.cs
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5000);
});

// Removed the app.UseHttpsRedirection();
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5000);
});

// Removed the app.UseHttpsRedirection();
This is what my launchSettings.json looks like;
`{
"profiles": {
"http": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://0.0.0.0:5000"
},
"https": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://0.0.0.0:7273;http://0.0.0.0:5022"
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}
`{
"profiles": {
"http": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://0.0.0.0:5000"
},
"https": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://0.0.0.0:7273;http://0.0.0.0:5022"
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}
No description
8 Replies
Pobiega
Pobiega2mo ago
You are binding to localhost, not all available interfaces Meaning only local connections are accepted
FestivalDelGelato
he is using ListenAnyIP tho
Pobiega
Pobiega2mo ago
Yes, but the launch message is quite clear So we must figure out why
FestivalDelGelato
i would try using --urls in the command line as a first test
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
electronic heartbreak.
Thanks for the replies. I gave it a go again without any changes and somehow it did not work at first, due to permission issues in Linux. But after fixing that I ran the stuff again and it works... http://{my-PI-IP}:5000/{my-endpoint}
No description
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?