使用com.sun.jersey.api.client.WebResource创建URI并向路径添加字符串值时出错

时间:2019-01-18 11:56:30

标签: rest webresource

使用com.sun.jersey.api.client.Client,ClientResponse和WebResource。

    Client client = this.client;
    WebResource webResource = null;
    ClientResponse response = null;
    String url = "";

url =“ https://test.com/rest/V1/cart/” + quoteId +“ / items”;

    webResource = client.resource(url);

    String jsonString = "{\"cartItem\":{\"quote_id\":" + quoteId + ",\"id\": " + id+ ",\"qty\":" + qty + "}}";

        ObjectMapper mapper = new ObjectMapper();
        JsonFactory factory = mapper.getFactory();
        JsonParser parser = factory.createParser(jsonString);
        JsonNode actualObj = mapper.readTree(parser);

        response = webResource.header("Authorization", "Bearer " + this.token).type("application/json")
                .post(ClientResponse.class, actualObj);

我有错误

  

索引52处路径中的非法字符:https://test.com/rest/V1/cart/“ IerwexsKLchKYmZ1ryKZkor9RdfJ2Dp3” /项目

我正在将quoteId作为参数String quoteId="IerwexsKLchKYmZ1ryKZkor9RdfJ2Dp3";

如何从URL中删除quoteId的引号? 谢谢。

0 个答案:

没有答案