0

我想将输入流从 android 发送到 servlet,但我认为我看不到与 android 中的流和 servlet 中的流进行通信的正确方法,这是两者的示例:android 方法:

    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);

请我需要帮助。

4

1 回答 1

0

如果您想发送输入流,您可以使用多部分/请求,例如在您上传文件的 Web 表单中。

于 2013-04-18T07:12:16.453 回答