I'm trying to write a byte buffer which contains this kind of strings &field_Value=
kggsW9YizUuRpjB/RtppZImnC8SekMGAWGnCmw+wPMwn7fWJva0QbSK/Slt/DDsZ
through a HttpURLConnection, but I receive &field_Value=
kggsW9YizUuRpjB/RtppZImnC8SekMGAWGnCmw wPMwn7fWJva0QbSK/Slt/DDsZ
So '+' is the only character which is not send. It happens with all my strings that contain a '+' inside.
Could you tell me how to encode the strings or what I'm doing wrong.
This is my code:
Sender:
url = new URL(url_globalApp);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream ());
//**************** first try ************//
wr.write(pairs_1.getBytes("UTF-8"), 0, pairs_1.length());
//**************** second try ************//
//wr.writeBytes(new String(pairs_1.getBytes(),"UTF-8"));
//**************** third try ************//
//wr.writeUTF(pairs_1);
wr.flush ();
wr.close ();
Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
Map <String,String[]> parameters = request.getParameterMap();
System.out.println(parameters.get("field_value_1")[0]);