rest - 使用 com.sun.jersey.api.client.WebResource 创建 URI 时出错,将字符串值添加到路径
问题描述
使用 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 的引号?谢谢你。
解决方案
推荐阅读
- xml - 使用来自单个 XML 节点的内容作为 XML 文档,同时在同一级别上提升 XML 节点
- r - 字符串AsFactors在数据框中的作用
- fabricjs - Fabric js - 如何使用鼠标事件绘制云形状?
- php - MySQL 查询缓存是否跨会话工作?
- matlab - Matlab Polarplot()和表面颜色
- azure - Azure Functions - TimerTrigger - 在本地运行时出错
- vue.js - Vue.js 无法在 safari 7.1 桌面上运行(旧版特立独行)
- php - 从两个表中获取数据
- python - Python 2D 精灵动画
- mysql - 从数据库中获取数据以在 Scala 中写入 Json 格式