首页 > 解决方案 > 为什么除了 Talend API tester 之外的每个客户端都可以使用此 REST 请求

问题描述

这是一个 REST POST 请求的示例,它可以在除 Talend API tester 之外的任何地方工作。它给出了 500 错误。

这是我在应用程序中设置请求的方式。

URLConnection connection = new URL("https://" + authHost + "/connect/token").openConnection();
logger.info("Connection oppened"); 
// message contains the form data: key=value&key=value&key=value
String message = "password=" + password + "&grant_type=password&username=" + username +
    "&client_id=foolid&scope=mouthwash";
logger.info(message); 
// Setting header fields. 
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Accept", "application/json");
connection.getOutputStream().write(message.getBytes("UTF-8"));

这是 Postman 中的一个工作示例

POST /connect/token HTTP/1.1
Host: identityserver.uat.example.com
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Cookie: ARRAffinity=6a37d2ecf3441e27913cb832c4b767c68cad0e45c8806b3c5344d1b52d57f67a; ARRAffinitySameSite=6a37d2ecf3441e27913cb832c4b767c68cad0e45c8806b3c5344d1b52d57f67a
Content-Length: 137

password=secret&grant_type=password&username=fool&client_id=foolid&scope=mouthwash

这是 Talend 所说的它发送的内容,它得到了 500 错误——据我所知,它来自服务器。

POST /connect/token HTTP/1.1
Accept: application/json
Content-Length: 137
Content-Type: application/x-www-form-urlencoded
Host: identityserver.uat.example.com

password=secret&grant_type=password&username=fool&client_id=foolid&scope=mouthwash

这里发生了什么事?

标签: apiresttalend

解决方案


推荐阅读