为什么模拟提交得不到正确结果
通过下面代码模拟提交时
public static String doPost(URL url, Properties nameValuePairs) throws
IOException {
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
Enumeration enum = nameValuePairs.keys();
while (enum.hasMoreElements()) {
String name = (String) enum.nextElement();
String value = nameValuePairs.getProperty(name);
char ch;
if (enum.hasMoreElements()) {
ch = '&';
}
else {
ch = '\n';
}
out.print(name + "=" + URLEncoder.encode(value) + ch);
}
out.close();
BufferedReader in;
try {
in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
}
catch (FileNotFoundException exception) {
InputStream err = ( (HttpURLConnection) connection).getErrorStream();
if (err == null) {
throw exception;
}
in = new BufferedReader(new InputStreamReader(err));
}
StringBuffer response = new StringBuffer();
String line;
while ( (line = in.readLine()) != null) {
response.append(line + "\n");
}
in.close();
return response.toString();
}
得到
“对不起,您的浏览器必须支持Cookie!”