2016-03-23 38 views
1

骆驼解码URL参数。 。有没有办法,我得到我发送的URL 我有以下情形(Spring的XML &骆驼):我可以阻止骆驼解码查询参数吗?

<route id="getDepResources"> 
     <from uri="restlet:/dep/{depId}/resources?restletMethods=GET"/> 
<bean ref="deptUtility" method="process" /> 
</route> 

public void process(Exchange exchange) throws Exception { 

    Message message = exchange.getIn(); 
    String body = message.getBody(String.class); 
    String uri = message.getHeader(Exchange.HTTP_URI, String.class); 
...... 
} 

curl -X GET 'http://localhost:8080/app1/dep/1/resources?resourceDesc=R%26B' --header "Content-Type:application/json" 

所以对于resourceDesc = R%26B(R & B)我需要得到它为R %26B,而我得到的第3行的URI是http://localhost:8080/app1/dep/1/resources?resourceDesc=R&B,而我认为它应该是http://localhost:8080/app1/dep/1/resources?resourceDesc=R%26B。有没有我可以做相同或任何其他方式的配置?请建议。

回答

0

它与骆驼直接无关,它与URI的规范有关:URI应该由UA解码。

如果您想按原样得到它,应该引用百分号字符。 %的报价是%25

+0

对不起,但我附加&as%26我:e resourceDesc = R%26B(R&B是实际文本)。我希望将它作为%26而不是&(保持原样的URL) – JD7

+0

message.getHeader(Exchange.HTTP_QUERY,String.class)也是这样做的。 – JD7

+0

因为它与骆驼相关:之前解码了URI。如果您希望您的应用程序获得R%26B,则必须对%,'R%2526B'进行编码。 –