jersey client syntactically incorrect 请求错误

jersey client syntactically incorrect request error

我一直在尝试 jersey 客户端从另一个 Web 服务使用我的 jax-rs Web 服务,每当我从 postman 发送 post 请求时,我一直收到这个 400 错误请求错误.我已经将球衣客户端配置为使用消息正文-reader 和我使用 Gson 自己实现的编写器。这是调用另一个 Web 服务的代码

 ClientConfig config = new ClientConfig();
         config.register(GsonWriter.class);
            config.register(GsonReader.class);

        Client client = ClientBuilder.newClient(config);
        WebTarget webTarget = client.target("http://localhost:8080/MessageBucket/MsgBucket/Api/bucket/msg");
        //WebTarget msgserviceWebTarget = webTarget.path("bucket/msg");
        System.out.println(webTarget.getUri());
        Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
        Response response = invocationBuilder.post(Entity.entity(msg, MediaType.APPLICATION_JSON));
        String bresponse = response.readEntity(String.class);
        System.out.println("after request");

        return bresponse;

我将作为参数传入我的其他 Web 服务的资源方法的 msg 对象。

我收到的错误 is:The 客户端发送的请求在语法上不正确。

原来我有 httpHeaders.get("Content-Type").add("charset=UTF-8");在我的 gson 提供程序 writeTo method.Once 行中,我将其注释掉,代码非常有效。