该问题通常是由于查询字符串参数的值包含特殊字符而导致的。可以使用UrlEncode方法对查询字符串参数进行编码。以下是示例代码:
C#代码:
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "hello")] HttpRequest req,
ILogger log)
{
string name = req.Query["name"];
string encodedValue = System.Web.HttpUtility.UrlEncode(name);
string responseMessage = $"Hello, {name}!";
log.LogInformation(responseMessage);
return new OkObjectResult(responseMessage);
}
在上面的代码中,我们使用了System.Web.HttpUtility.UrlEncode方法对查询字符串参数进行了编码,从而避免了特殊字符的问题。