0
我正在創建示例應用程序,它將XML文件發送到本地服務器。在服務器端,我需要讀取客戶端發送的數據並將其寫入新文件。如何讀取服務器端由HttpPost發送的數據
下面是我用來讀取XML文件並將其發送到服務器的客戶端代碼。
HttpClient httpclient = new DefaultHttpClient();
// Below code is used to connect with the local tomact server or servlet
HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx:yyyy");
File file = new File("C:\\Files\\sample.xml");
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
int respcode = response.getStatusLine().getStatusCode();
System.out.println("respcode: " + respcode);
請讓我用tomact如何從客戶端獲取數據,並將其寫入服務器端知道。我是否需要使用servlet來處理這個問題?
我曾經訪問過很多博客,但我沒有得到如何創建一個服務器端代碼來完成這項任務。
在此先感謝!
感謝您的回覆閱讀。我會嘗試使用上述。我還有一個問題,'http://xxx.xxx.xxx.xxx:yyyy'我在客戶端提到的連接url應該包含哪個url?對於端口我可以指定tomcat端口。但是url呢? –