C # Uri.EscapeDatastring () equivalent for Java

We have implemented an HTTP authentication connection encoded in C # using Uri.EscapeDataString() .

I am trying to create an identical Java test application that does the same as the C # version, but URLEncoder.encode(string, "UTF-8") adds an extra encoding that is not quite the same as the C # Uri.EscapeDataString() .

What is the equivalent coding method?

+6
source share
3 answers

The best way I've found this is to use the URL.toURI().toString() command:

 String uriEncodeVariable = "https://localhost:443"; URL tempURL = new URL(uriEncodeVariable); String uriResult = tempURL.toURI().toString(); 
+2
source

Take a look at Apache StringScapeUtils , one of the methods of this class will certainly be useful.

0
source

I'm not very fluent in C #, but it looks like you need something like URLEncoder? Let's take a look at SO 213506 (http://stackoverflow.com/questions/213506/java-net-urlencoder-encodestring-is-deprecated-what-should-i-use-instead)?

-1
source

Source: https://habr.com/ru/post/902700/


All Articles