HttpsURLConnection setRequestMethod("POST") sends the request as GET
843811Nov 13 2003 — edited Apr 19 2004Hello,
I am facing a strange problem.
I am using com.sun.net.ssl.HttpsURLConnection and use the setRequestMethod to set the request method as POST. but on the other end, it always goes as a GET.
Attached is the code below..could anyone give me an idea as to what could be the problem?
Thanks,
Chitra
URL objUrl = null;
HttpsURLConnection urlc = null;
try {
objUrl = new URL("https://test:81/servlet/TestServlet");
urlc = (HttpsURLConnection)objUrl.openConnection(); //from secure site
} catch (Exception e) {
e.printStackTrace();
}
System.out.println (" After getting the connection ");
if (urlc == null || objUrl == null) {
System.out.println (" error here ");
}
urlc.setUseCaches(false);
urlc.setDoInput(true);
urlc.setDoOutput(true);
urlc.setRequestMethod("POST");
String strTest = "Testing TEsting testing ";
System.out.println (urlc.toString());
System.out.println (" Request method is " + urlc.getRequestMethod());
OutputStream out = urlc.getOutputStream();
out.write(strTest.getBytes());
out.flush();
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
objUrl.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();