HTTP URL Address Encoding in Java

前端 未结 26 1714
醉酒成梦
醉酒成梦 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:18

    I've created a new project to help construct HTTP URLs. The library will automatically URL encode path segments and query parameters.

    You can view the source and download a binary at https://github.com/Widen/urlbuilder

    The example URL in this question:

    new UrlBuilder("search.barnesandnoble.com", "booksearch/first book.pdf").toString()
    

    produces

    http://search.barnesandnoble.com/booksearch/first%20book.pdf

提交回复
热议问题