Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Empty string cannot be passed in HttpTrigger query string

未关闭
#683 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@kamperiadis 已经在做这个了。

开始于 2023年1月6日。

  • #694 来自 @kamperiadis —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

area:java-functions Break Change Enhancement needs-discussion New Feature reviewed
Repro steps
  1. Run the following function from templates:
package com.function;

import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

/**
 * Azure Functions with HTTP Trigger.
 */
public class HttpTriggerJava1 {
    /**
     * This function listens at endpoint "/api/HttpTriggerJava1". Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP Body" {your host}/api/HttpTriggerJava1
     * 2. curl {your host}/api/HttpTriggerJava1?name=HTTP%20Query
     */
    @FunctionName("HttpTriggerJava1")
    public HttpResponseMessage run(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");

        // Parse query parameter
        String query = request.getQueryParameters().get("name");
        String name = request.getBody().orElse(query);

        if (name == null) {
            return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
        } else {
            return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
        }
    }
}
  1. Send the following request: http://localhost:7071/api/HttpTriggerJava1?name=
Expected behavior

name should be set to an empty string and the function should return "Hello, "

Actual behavior

name is set to null and the function returns "Please pass a name on the query string or in the request body"

Known workarounds

None

Related information

Similar issue in PowerShell worker: https://github.com/Azure/azure-functions-powershell-worker/issues/895

主要语言
Java
星标
103
派生
74
平均合并
12 小时 49 分钟
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/azure-functions-java-worker 的其他 Issue

查看 Azure/azure-functions-java-worker 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。