9

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?

John Leehey
  • 22,052
  • 8
  • 61
  • 88

2 Answers2

3

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();
John Leehey
  • 22,052
  • 8
  • 61
  • 88
-1

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

Michael Zilbermann
  • 1,398
  • 9
  • 19