3

I have an ASP.NET Core 7 Web API service implemented in C# and a method defined like this:

[ApiController]
[Route("api/[controller]")]
public class SensorsController : ControllerBase
{
    // ...
    [HttpGet("{sensorname}/zf")]
    public async Task<ActionResult> GetZForecast(string sensorname, [FromQuery]DateTime? when, [FromQuery]string? wind)
    {
        // ...
    }
}

I want to test it with this curl command:

curl -X get https://localhost:7091/api/Sensors/VK_THC_GreenRoom/zf?when="2025-03-15T08:00:00Z"&wind="Calm"

Why is the wind parameter not captured by the controller in this case?

enter image description here

If I use only one of the optional query parameter like shown below, then all works just fine and both wind and when are captured respectively:

curl -X get https://localhost:7091/api/Sensors/VK_THC_GreenRoom/zf?when="2025-03-15T08:00:00Z"

curl -X get https://localhost:7091/api/Sensors/VK_THC_GreenRoom/zf?wind="Calm"

So what am I missing ?

3
  • See if answer here helps : stackoverflow.com/questions/59621053/…. Look at the HTTPGet in the answer. Commented Mar 22 at 18:24
  • Thanks @jdweng but I think that is a different story and is not applicable here. Route is the same and is correct in all cases, it is rather the query parameter which is not parsed in some way. Commented Mar 22 at 18:35
  • Remove the quotes from the URL, you don't need it for the query param value: https://localhost:7091/api/Sensors/VK_THC_GreenRoom/zf?when=2025-03-15T08:00:00Z&wind=Calm Commented Mar 23 at 1:35

1 Answer 1

1

In curl The entire URL should be enclosed in quotes to ensure that the shell interprets it correctly:

curl -X GET "https://localhost:7091/api/Sensors/VK_THC_GreenRoom/zf?when=2025-03-15T08:00:00Z&wind=Calm"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.