i am new to Android Studio and making app using WordPress Website as backend , i want users ti post comment on posts which is working well but i want to tell users if their comment has been submitted successfully or got any error.. this is my code
OkHttpClient httpClient = new OkHttpClient();
Request request = new Request.Builder()
.url("https://www.sikhnama.com/?json=respond/submit_comment&post_id=" Postid
"&name=" name "&email=" email "&content=" comment)
.build();
try {
Response response = httpClient.newCall(request).execute();
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();
}
});
} catch (IOException e) {
e.printStackTrace();
Log.d("Comment", "Comment Failed");
}
i have log "comment failed" but it never comes even if failed comment.. please help
CodePudding user response:
See the documentation for OkHttpClient
. Execution of the call will not throw an exception in case of an http error response code (and it would be a very bad library design if it did so), only on network failure, interruption etc.
You can check the reponse.isSuccessful()
and log your "comment failed" message or whatever.