簡體   English   中英

如何在HttpPost發送的服務器端讀取數據

[英]How to read data at server side sent by HttpPost

我正在創建將XML文件發送到本地服務器的示例應用程序。 在服務器端,我需要讀取客戶端發送的數據並將其寫入新文件。

下面是我用來讀取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來處理嗎?

我訪問了許多博客,但是我沒有獲得如何創建服務器端代碼來完成此任務的方法。

提前致謝!

是的,您需要編寫一個servlet /過濾器來處理此問題。 Servlet收到HttpServletRequest對象后,

您可以使用HttpServletRequest.getInputStream()方法閱讀它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM