After changing the writeEncodedContent method, I can get rid the error off from my program.
The changes are:
Code:
private void writeEncodedContent(String encodedContent) {
DataOutputStream writer;
HttpsURLConnection connection = null;
encodedContent = "content=" + encodedContent;
try {
connection = (HttpsURLConnection) new URL("https://10.8.8.40").openConnection();
connection.setRequestProperty("User-Agent", "IFXClient");
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/plain");
connection.setRequestProperty("Content-Length", "" + encodedContent.length());
connection.connect();
} catch (IOException e) {
e.printStackTrace();
}
try {
writer = new DataOutputStream(connection.getOutputStream());
writer.writeBytes(encodedContent);
writer.flush();
writer.close();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
And the server code for handling the request is :
Code:
public ProcessConnection(Socket s) { // constructor
client = s;
try {
is = new BufferedReader(new InputStreamReader
(client.getInputStream()));
os = new DataOutputStream(client.getOutputStream());
} catch (IOException e) {
System.out.println("Exception: "+e.getMessage());
}
System.out.println("Processing connection from " + s.getInetAddress().toString());
this.start(); // Thread starts here...this start() will call run()
}
public void run() {
try {
// get a request and parse it.
String request = is.readLine();
System.out.println( "Request: "+request );
} catch (Exception e) {
System.out.println("Exception: " +
e.getMessage());
}
}
The error is gone, but the request become NULL when I try to post. I don't have any problem for GET message.
Please advice.
Thank you in advance.
Wisnu (WishKnew)