0

Android からサーブレットに入力ストリームを送信したいのですが、Android のストリームとサーブレットのストリームと通信する正しい方法が見当たらないので、両方のサンプルを次に示します: 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;
}

サーブレットコードは次のとおりです。

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 に答える