Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导REST API无法识别的令牌_Java_Spring_Spring Boot_Docker_Traefik - Fatal编程技术网

Java Spring引导REST API无法识别的令牌

Java Spring引导REST API无法识别的令牌,java,spring,spring-boot,docker,traefik,Java,Spring,Spring Boot,Docker,Traefik,我有一个RESTAPI和一个请求该API的WEB应用程序。两者都在春季启动。 我在postman中遵循并测试了API,效果很好。 我还从我的webapp测试了API,它也工作了 但是当我用Traefik在docker中运行API时,我得到了一个错误,但仅来自webapp。邮递员仍然工作得很好 2020-10-27T13:31:10.334026053Z at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown

我有一个RESTAPI和一个请求该API的WEB应用程序。两者都在春季启动。 我在postman中遵循并测试了API,效果很好。 我还从我的webapp测试了API,它也工作了

但是当我用Traefik在docker中运行API时,我得到了一个错误,但仅来自webapp。邮递员仍然工作得很好

2020-10-27T13:31:10.334026053Z  at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:na],
2020-10-27T13:32:34.827929610Z java.lang.RuntimeException: Could not read 
requestcom.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ssword': was expecting 
(JSON String, Number, Array, Object or token 'null', 'true' or 'false')
在请求中,我将用户名和密码作为json发布在正文中,如下所示:

{
    "username" : "user",
    "password" : "dfgdhghdhdhfd"
}
这是从webapp生成请求的代码:

JsonObject j = new JsonObject();
    j.addProperty("username", API_USER);
    j.addProperty("password", API_PASSWORD);

HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("http://myapi.local/login"))
                .header("Content-Type", "application/json")
                .POST(BodyPublishers.ofString(j.toString()))
                .timeout(Duration.ofSeconds(2L))
                .build();
        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
        return response.headers().firstValue("Authorization").get();
JsonObject j=新的JsonObject();
j、 addProperty(“用户名”,API_用户);
j、 addProperty(“密码”,API_密码);
HttpClient=HttpClient.newHttpClient();
HttpRequest请求=HttpRequest.newBuilder()
.uri(uri.create(“http://myapi.local/login"))
.header(“内容类型”、“应用程序/json”)
.POST(bodypublisher.ofString(j.toString()))
.超时(持续时间秒(2L))
.build();
HttpResponse response=client.send(请求,BodyHandlers.ofString());
返回response.headers().firstValue(“授权”).get();
当它引用“password”密钥的后半部分时,是否有可能被截断?我甚至不知道从哪里开始获取信息来帮助你帮助我

总结如下:

  • Localhost webapp和邮递员到Localhost的API:Works
  • Localhost-postman-to-Docker-API:Works
  • Localhost webapp到Docker API:不工作

你能系统输出“bodypublisher.ofString(j.toString())”吗?你能系统输出“bodypublisher.ofString(j.toString())吗?它匹配,这是从j.toString:
{“username”:“user”,“password”:“dfgdhghdhfd”}
你能系统输出“bodypublisher.ofString(j.toString())”吗?你能系统输出“bodypublisher.ofString(j.toString())”吗?它匹配吗,这是来自j.toString:
{“用户名”:“用户”,“密码”:“dfgdhghdhfd”}