Posted By:
Ross_Cooksey
Posted On:
Thursday, June 14, 2001 02:03 PM
I have the following code: URL url = new URL(new String("http://localhost:7001/TestContent?fn=803.txt")); URLConnection connection = url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream instrm = connection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(instrm)); String msg = null; while ((msg = in.readLine()) != null) System.out.println(msg); All is well and good. The result is just plain text from the servlet indicating that the doGet method was executed. When the code is modified as follows: URL url = new URL(
More>>
I have the following code:
URL url = new URL(new String("http://localhost:7001/TestContent?fn=803.txt"));
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream instrm = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(instrm));
String msg = null;
while ((msg = in.readLine()) != null)
System.out.println(msg);
All is well and good. The result is just plain text from the servlet indicating that the doGet method was executed.
When the code is modified as follows:
URL url = new URL(new String("http://localhost:7001/TestContent?fn=803.txt"));
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.connect();
InputStream instrm = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(instrm));
String msg = null;
while ((msg = in.readLine()) != null)
System.out.println(msg);
things fall apart. I get back >Error 400--Bad Request
<
In looking at the access.log file I see the following log statements (the GET works, the POST does not):
127.0.0.1 - - [14/Jun/2001:15:20:33 -0400] "GET /TestContent?fn=803.txt HTTP/1.0" 200 0
127.0.0.1 - - [14/Jun/2001:15:21:27 -0400] "POST /TestContent?fn=803.txt HTTP/1.0" 400 1296
Any thoughts? Thanks in advance.
<<Less