使用 HttpPost 上传完整事件

Upload complete event using HttpPost

我的应用程序将图像上传到服务器。为了执行上传,我使用 HttpPost class。这是相关的代码片段:

try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("%PATH_TO_SERVER_PAGE%");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    httpclient.execute(httppost);
} catch (Exception e) {
    System.out.println("Connection error: " + e.toString());
}

我的问题是如何引发事件并知道上传是否已成功完成以确保文件已在服务器上?

谢谢。

观察者设计模式的实施可能是一个合适的解决方案。
参考: