Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Uri.EscapeDatastring() equivalent for Java

Tags:

java

c#

urlencode

We've implemented an HTTP authentication connection, encoded in C# with Uri.EscapeDataString().

I'm trying to make an identical java test application that does the exact same thing as the C# version, but URLEncoder.encode(string, "UTF-8") adds additional encoding that isn't quite the same as the C# Uri.EscapeDataString() function.

What's the equivalent encoding method?

like image 244
John Leehey Avatar asked Nov 29 '11 20:11

John Leehey


1 Answers

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

String uriEncodeVariable = "https://localhost:443";
URL tempURL = new URL(uriEncodeVariable);
String uriResult = tempURL.toURI().toString();
like image 78
John Leehey Avatar answered Nov 15 '22 07:11

John Leehey