Hi! Friends,
My problem might seem to be a repetitive one, but am not able to debug it. I have written a class which invokes a Servlet using net package but is giving an error.
The code snippet of class is as follows:
public static void main(String args[])
{
URL url = new URL("http://12.125.0.15/MyProj/servlet/MyServlet");
URLConnection con = url.openConnection();
System.out.println("Received a : " + con.getClass().getName());
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
System.out.println("Getting an output stream...");
OutputStream os = con.getOutputStream();
String msg = "Message from client";
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(msg);
osw.flush();
osw.close();
System.out.println("After flushing output stream. ");
System.out.println("Getting an input stream...");
InputStream is = con.getInputStream();
// any response?
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
......
}
When I execute this code from the command line, it gives an error as such:
java.io.IOException: Server returned HTTP response code: 405 for URL:
http://12.125.0.15/sec/servlet/MailServlet at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at GoodURLPost.main(GoodURLPost.java:38)
...........................................................................
I have tried the links I found on Javaranch for the similar problem but in vain. Can anybody rectify the mistake or suggest something.
Thanks,
-Navin.