Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chi phí đã được phê duyệt hoặc bị từ chối bởi người dùng hiện hành động trong vai trò người giữ ngân sách. Các chủ đề đồng bộ hóa giao tiếp với máy chủ bằng cách sử dụng giao thức HTTP. Yêu cầu định dạng XML có chứa tất cả các thông tin rằng thiết bị này muốn trao đổi được gửi đi. | 2 72 MIDP 2.0 CASE STUDIES expenses that have been approved or rejected by the current user acting in the budget holder role. The synchronization thread communicates with the server using the HTTP protocol. XML formatted requests that contain all the information that the device wishes to exchange are sent. After processing the request the server formats an XML response containing updates. XML is space inefficient many additional bytes are required to encode information. So why use XML in an environment where memory is at a premium and the network connections are slow XML is convenient it is easy to validate and there are many existing tools and APIs to simplify its use allowing the expense application prototype to be created in the minimum of time. The javax.microedition.io.HttpConnection class is used for the server communication. Requests to the server use a utility method sendMessageToServer that has a single parameter containing the XML request to be sent. An HttpConnection is opened to the server URL and the XML request sent via the connection s Outputstream. The response is read into a StringBuffer before being returned to the caller. If there is an error then an exception is thrown that will eventually find its way back to the synchronization form to be presented to the user. SynchronizationThread sendMessageToServer method private String sendMessageToServer String message throws IOException ServerCommException StringBuffer sb new StringBuffer HttpConnection connection null InputStream is null open connection connection HttpConnection Connector.open settings.getSyncServer send message to server OutputStream os connection.openOutputStream os.write message.getBytes os.close make sure we got a good response code i.e. 200 300 if connection.getResponseCode 200 connection.getResponseCode 300 is connection.openInputStream byte buffer new byte 512 int bytesRead 0 while -1 bytesRead is.read buffer 0 512 sb.append new String buffer 0 bytesRead else error of some kind