Rest URL編碼問題


The URI specification only allows certain characters within a URI string. It also reserves

certain characters for its own specific use. In other words, you cannot use these char-
acters as part of your URI segments. This is the set of allowable and reserved characters:
• The US-ASCII alphabetic characters a–z and A–Z are allowable.
• The decimal digit characters 0–9 are allowable.
• All these other characters are allowable: _-!.~'()*.
• These characters are allowed, but are reserved for URI syntax: ,;:$&+= ?/[]@.
All other characters must be encoded using the “%” character followed by a two-digit
hexadecimal number. This hexadecimal number corresponds to the equivalent hexa-
decimal character in the ASCII table. So, the string bill&burke would be encoded as
bill%26burke.
When creating @Path expressions, you may encode its string, but you do not have to.
If a character in your @Path pattern is an illegal character, the JAX-RS provider will
automatically encode the pattern before trying to match and dispatch incoming HTTP
requests. If you do have an encoding within your @Path expression, the JAX-RS provider
will leave it alone and treat it as an encoding when doing its request dispatching. For
example:
@Path("/customers"
public class CustomerResource {
   @GET
   @Path("roy&fielding")
   public String getOurBestCustomer() {
      ...
   }
}
The @Path expression for getOurBestCustomer() would match incoming requests like
GET /customers/roy%26fielding.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章