Java休息:400。请求形成不佳:URL包含 - > API/组件(848569)/properties(利益相关者|应用程序管理器')

发布于 2025-02-11 02:10:51 字数 1439 浏览 1 评论 0原文

我的URL是:

https://te.avolutionsoftware.com/api/Components(848569)/Properties('Stakeholder|Application Manager')

当我使用时,

    allowMethods("PATCH");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    String auth = bearerToken;
    //byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
    String authHeaderValue = "Bearer " + new String(auth);
    conn.setRequestProperty("Authorization", authHeaderValue);
    //conn.setRequestProperty("X-HTTP-Method-Override", "PATCH");
    
    conn.setRequestMethod(method);
    conn.setRequestProperty("Content-Type", "application/json");
    String input = data;//"{\"qty\":100,\"name\":\"iPad 4\"}";
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Length", String.valueOf(input.length()));
    OutputStream os = conn.getOutputStream();
    os.write(input.getBytes());
    os.flush();

请始终给出

    <HTML><HEAD><TITLE>Bad Request</TITLE><META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD><BODY><h2>Bad Request</h2><hr><p>HTTP Error 400. The request is badly formed.</p>

我的JSON主体:

 {"Value": "Update Test"}

相同的Java方法在带有不同URL的“发布”方面正常工作。

URL在Postman中与补丁和相同的JSON身体字符串正常工作。

任何建议在这里可能出现什么

My URL is:

https://te.avolutionsoftware.com/api/Components(848569)/Properties('Stakeholder|Application Manager')

When i am using

    allowMethods("PATCH");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    String auth = bearerToken;
    //byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
    String authHeaderValue = "Bearer " + new String(auth);
    conn.setRequestProperty("Authorization", authHeaderValue);
    //conn.setRequestProperty("X-HTTP-Method-Override", "PATCH");
    
    conn.setRequestMethod(method);
    conn.setRequestProperty("Content-Type", "application/json");
    String input = data;//"{\"qty\":100,\"name\":\"iPad 4\"}";
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Length", String.valueOf(input.length()));
    OutputStream os = conn.getOutputStream();
    os.write(input.getBytes());
    os.flush();

Always give

    <HTML><HEAD><TITLE>Bad Request</TITLE><META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD><BODY><h2>Bad Request</h2><hr><p>HTTP Error 400. The request is badly formed.</p>

My JSON body:

 {"Value": "Update Test"}

Same java method working fine for "POST" with different URL.

URL working fine in Postman with Patch and same Json Body String.

Any suggestion what could be issue here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文