1

I am trying to use a domain as a query param in an Azure Function app.

Something like this:

/api/foo/bar/{url}
/api/foo/bar/https%3a%2f%2flocalhost%3a3000

This doesn't hit the function (although it works locally, although is automatically decodes the : which is annoying), is this as expected? (it does work if I had it as a query string)

5
  • Can you please provide more details on your requirement? Also please share your function code Commented Jun 21, 2024 at 4:41
  • i am not sure what else you need, a c# function has a route set to the route above, and when i send the route with a value it says resource not found and doesn't hit the function, eg no function is processed. Commented Jun 21, 2024 at 11:31
  • can you please share your function code? Commented Jun 21, 2024 at 11:36
  • I am getting this output and my function is triggered too. Are you looking for this solution? Commented Jun 21, 2024 at 11:59
  • if you read the op, it says it works locally although it decodes the :, so the value isn't consistants but doesn't work in azure as a live function Commented Jun 21, 2024 at 12:02

1 Answer 1

2

You need to use the double encoded URL in the request while running in function app. Pass https%253a%252f%252flocalhost%253a3000 instead of https%3a%2f%2flocalhost%3a3000 while invoking the function in function app.

I have below function code which is deployed to function app.

[FunctionName("Function1")]
public static async Task<IActionResult> 
    Run([HttpTrigger(AuthorizationLevel.Anonymous, 
                     "get", "post", 
                      Route = "foo/bar/{encodedUrl}")] 
                           HttpRequest req,
        string encodedUrl, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string decodedUrl = HttpUtility.UrlDecode(encodedUrl);

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    string responseMessage = string.IsNullOrEmpty(name)
        ? $"This HTTP triggered function executed successfully. The decoded URL is: {decodedUrl}. Pass a name in the query string or in the request body for a personalized response."
        : $"Hello, {name}. This HTTP triggered function executed successfully. The decoded URL is: {decodedUrl}.";

    return new OkObjectResult(responseMessage);
}

I am passing the value of encodedUrl as https%253a%252f%252flocalhost%253a3000 and it worked as expected.

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

thanks, is there a reason this is happens like this?
I believe single encoded URL is getting decoded and the initial url breaks hence throwing 404.
would you consider that a bug which requires reporting?
Yes. More importantly we can't get the error logs for this issue as its a not found case
thanks for the help, i am gunna use querystring for stability, ill report the issue and if it gets sorted i might revert back
|

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.