I did this implementation to send a Post message to my servlet:
String urlParameters = "my_file="+LargeString;
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String req = "http://localhost:8080/MyServlet1";
URL url = new URL( req );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
In myServlet1 i try to retreive this data by using:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String mydata_serialized = request.getParameter("my_file");
System.out.println(mydata_serialized);
}
Nothing happen. Even if i print a simple message such as System.out.println("Hello");
in doPost
nothing happen. This is proof that the message is not sent to doPost
How can I retreive the message sent please ?