我的API
端点看起来像
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("groups/{groupName}")
public Response getCategoriesByGroupName(@PathParam("groupName") @Nonnull final String groupName) {
return Response.ok(getCategoryTO().getCategoriesByGroupName(categoryManager, groupName)).build();
}
当我尝试按
命中端点时curl -H"Content-Type: application/json" -H"BEARER:792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000" "https://myapp.com/rest/categories/groups/Utilities"
我得到了正确的JSON
,意味着groupName
被Utilities
正确替换
但是当我做的时候
curl -H"Content-Type: application/json" -H"BEARER:792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000" "https://myapp.com/rest/categories/groups/Food & Drink"
我将服务器错误视为
Caused by: javax.ejb.EJBException: javax.persistence.NoResultException: no categories exists with groupName: Food
问题是groupName
被替换为Food
而不是Food & Drink
我尝试了其他groupName
,并意识到每当我的groupName
有空格时,只有第一个单词被替换为groupName
如何解决此问题,以便URL
中传递的整个字符串变为groupName
?
我的服务器部署在Wildfly 8
答案 0 :(得分:0)
这与我的终点无关。
如@Sotirios所述,我需要在将URL发送到服务器之前对其进行编码。
当我做那件事开始工作时
curl -H"Content-Type: application/json" -H"BEARER: 792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000" "https://myapp.com/rest/categories/groups/Food%20%26%20Drink"
[{"id":"9b1e97f2-ac7d-4caf-85fc-476cd97dd6cb","name":"Alcohol & Bars","groupName":"Food & Drink"}]