Java HTTP/XML-request with special characters

machkimx

New Member
I'm setting up an HTTP-request to the Google geocoding API via a Java servlet. Unfortuately, everytime this request contains a special character (e.g. the '?'), the request returns an "Bad request / 400" exception. Since this service is about to be used in countries where these weird characters are fairly popular and neccessary - Europe - I'm having a little bit of trouble here.Replacing the special characters with their hexadecimal escape String (0xDF/%DF for the '?') in the request result in a "INVALID_REQUEST" response from Google. This is how i get the XML-response:\[code\]stringToReverse = URLEncoder.encode(url, "UTF-8");URL urlR = new URL(url); URLConnection connection = urlR.openConnection(); connection.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); out.write("string=" + stringToReverse); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String decodedString; String resultString = ""; while ((decodedString = in.readLine()) != null) { System.out.println(decodedString); resultString += decodedString; } in.close();\[/code\]Hopefully someome can help me out here. I suppose the URLConnection or one of the streams need to be set to UTF-8, considering Google's response is encoded in UTF-8 as well?!
 
Back
Top