iSeriesCodePoet
Programmer
History:
I am trying to do a "proof of concept" program to post files to a new purchased web application we have. I am trying to interface with the sevlet (I assume since it runs on Tomcat) using java. So co-workers of mine (who conveniently went on vaction left me with the sample. Well, since I have never worked with this sort of thing before I figured I would try connecting to Google first, so I don't mess up the application.
Problem:
Well, the sample of mine doesn't seem to work right, I keep on getting an error code 501 - Not Implemented error. The code I have posted below. What could be going wrong? Could Google be blocking those kind of requests?
Code:
Any help would be appreciated! iSeriesCodePoet
IBM iSeries (AS/400) Programmer
I am trying to do a "proof of concept" program to post files to a new purchased web application we have. I am trying to interface with the sevlet (I assume since it runs on Tomcat) using java. So co-workers of mine (who conveniently went on vaction left me with the sample. Well, since I have never worked with this sort of thing before I figured I would try connecting to Google first, so I don't mess up the application.
Problem:
Well, the sample of mine doesn't seem to work right, I keep on getting an error code 501 - Not Implemented error. The code I have posted below. What could be going wrong? Could Google be blocking those kind of requests?
Code:
Code:
import java.io.*;
import java.net.*;
public class Test {
public static void main(String[] args) {
try {
// make the connection
String urlstring = "[URL unfurl="true"]http://www.google.com/search";[/URL]
String parameters = "q=Mike+Wills";
URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
// post the parameters
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-length", String.valueOf(parameters.length()));
OutputStreamWriter wr;
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(parameters);
wr.flush();
wr.close();
// now let's get the results
conn.connect();
int responseCode = conn.getResponseCode();
String responseMsg = conn.getResponseMessage();
System.out.println(responseCode + " - " + responseMsg);
if (responseCode > 200 && responseCode < 300){
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer results = new StringBuffer();
String oneline;
while ( (oneline = br.readLine()) != null) {
results.append(oneline);
}
br.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Any help would be appreciated! iSeriesCodePoet
IBM iSeries (AS/400) Programmer