问题描述是:客户端可以访问到服务器,但是服务器接受到的参数却为空。
发送请求源码:
URL postURL=new URL(url);
conn = (HttpURLConnection)postURL.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Language","en-CA");
conn.setRequestProperty("Accept","text/javascript, text/ecmascript, application/x-javascript, */*, text/x-vcard, text/x-vcalendar, image/gif, image/vnd.wap.wbmp,textnd.wap.wml,applicationnd.wap.xhtml+xml,textml,text/css,text/vnd.wap.wml,application/vnd.wap.xhtml+xml,text/html,text/css");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Cache-Control", "no-cache");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestProperty("Charset", "UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
dos=new DataOutputStream(conn.getOutputStream());
dos.write(property.getBytes("UTF-8"));
dos.flush();
服务器端源码:
try {
stream = request.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
while ((string = br.readLine()) != null) {
sb.append(string);
}
} catch (IOException e2) {
e2.printStackTrace();
}
String sstr = sb.toString();
System.out.println(sstr);
服务器上打印 sstr为空,不知道是什么原因。。。请求帮助