使用 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"/items
我将 quoteId 作为参数传递String quoteId="IerwexsKLchKYmZ1ryKZkor9RdfJ2Dp3";
如何从 URL 中删除 quoteId 的引号?谢谢你。