1

メソッドの接続解除元HttpURLConnection正しく機能していないようです。次のコードを実行すると:

url = new URL("http:// ...");
connection = (HttpURLConnection) url.openConnection ();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
// Some code
connection.disconnect();
connection.setDoInput(false); // -> IllegalStateException

IllegalStateExceptionメソッドを呼び出すとが得られsetDoInputます。例外は言う:

接続済み

4

1 に答える 1

1

接続を再利用しようとしているようですね。つまり、サーバーから切断した後にリクエストのプロパティを変更し、別の接続を確立する準備をします。

その場合は、新しいHttpURLConnectionオブジェクトを作成してください。

于 2010-01-15T18:16:53.590 に答える