2013-04-18 85 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表单中一样。