2013-04-18 88 views
0

我想從Android發送輸入流到一個servlet,但我不認爲我可以看到正確的方式來與Android中的流進行通信和在servlet流,這裏是兩個樣本: Android的方法:Android :: Servlets,我想沖洗一個流到一個servlet

private InputStream getHttpConnection(String urlString) throws IOException { 
    InputStream stream = null; 
    URL url = new URL(urlString); 
    URLConnection connection = url.openConnection(); 

    try { 
     HttpURLConnection httpConnection = (HttpURLConnection) connection; 
     httpConnection.setRequestMethod("GET"); 
     httpConnection.setRequestProperty("name", "TheKeyword"); 
     httpConnection.connect(); 

     if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { 
      stream = httpConnection.getInputStream(); 

     } 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
    return stream; 
} 

這裏是servlet代碼:

inputStream = new DataInputStream(request.getInputStream()); 
     content = request.getParameter("name"); 


     if (content.equals("TheKeyword")) { 
      ServerResponse = "32.024851:35.877249;31.9565783:35.945695;32.0833:36.1000;31.56:35.56;"; 
     } else { 
      ServerResponse = "32.024851:35.877249;31.56:35.56;"; 
     } 

    } catch (Exception e) { 
     // // TODO: handle exception 
     System.out.println(ServerResponse); 
    } 

    response.getOutputStream().print(ServerResponse); 

請我需要幫助。

+0

你有什麼問題呢?例外? – shazin 2013-04-18 06:34:23

+0

對不起,我的壞,我想檢查關鍵字,因爲後來我會有更多的關鍵字,每個人會返回的東西,感謝您的關注。 – Tayseer 2013-04-18 06:38:02

回答

0

如果你想發送一個輸入流,你可以使用multipart/request,就像在你上傳文件的web表單中一樣。