1
我使用下面的代碼發送數據到一個servlet: 當encoding =「UTF-8」或「GBK」時,數據被正確接收。 但是,當encoding =「UTF-16」時,接收器接收到null。爲什麼??URL參數編碼/接收問題
發件人:
URL url = new URL(notifyURL);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=" + encoding);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("notify_id=" + URLEncoder.encode("123", encoding) + "¬ify_type=" + URLEncoder.encode("any", encoding));
out.flush();
out.close();
connection.connect();
接收器的servlet:
log.info(request.getParameter("notify_type")); //print null