HTTP URL Address Encoding in Java

前端 未结 26 1346
醉酒成梦
醉酒成梦 2020-11-22 01:35

My Java standalone application gets a URL (which points to a file) from the user and I need to hit it and download it. The problem I am facing is that I am not able to encod

26条回答
  •  清酒与你
    2020-11-22 02:15

    This is more of a note than an answer. For the above, commons http client URIUtil is still the most convenient and straightforward method to encode different parts of an URI. Unfortunately it is deprecated, the reason cannot be immediately ascertained. Though URIUtil may not cover all the corner cases, it is still the most uncomplicated approach.

    I have searched for many library/methods to do this, however, none of them (my view here) provided a simple approach.

    I finally took the URIUtil and its dependency code and recompiled, which is working very well for me.

    While I don't expect anyone to follow this approach, however, if someone requires, below are the dependencies for compilation (from commons http client 3):

    1. org.apache.commons.httpclient.URIException
    2. org.apache.commons.httpclient.HttpClientError
    3. org.apache.commons.httpclient.NameValuePair
    4. org.apache.commons.httpclient.util.LangUtils
    5. org.apache.commons.httpclient.util.URIUtil
    6. org.apache.commons.httpclient.URI
    7. org.apache.commons.httpclient.util.EncodingUtil

提交回复
热议问题