ユーザーがJButtonをクリックすると、Webサイトのphpスクリプトに接続してデータを送信し、PHPスクリプトから結果を取得するswingアプリケーションがあります。
これは、このアプリケーションを使用した何百人ものユーザーにとっては問題なく機能しましたが、今日、ある会社のユーザーの 1 人が、これを使用できないと報告しました...彼がボタンをクリックすると、アプリケーションがハングし、何も起こりません。
アプリケーションで予期しない例外を処理するために UncaughtExceptionHandler を使用することさえありますが、何もスローされません。彼の会社のネットワークか、使用されているポートの何かではないかと思いましたが、よくわかりません。なぜこれが起こるのでしょうか?
これが私のコードです:
String part1 = "..."; // Message part 1.
String part2 = "..."; // Message part 2.
//1. Encode the message to suite the URL path requirements :
String params = URLEncoder.encode( "part1", "UTF-8" ) + "=" + URLEncoder.encode( part1, "UTF-8" );
params += "&" + URLEncoder.encode( "part2", "UTF-8" ) + "=" + URLEncoder.encode( part2, "UTF-8" );
//2. Connect to the website page :
URL url = new URL( "http://www.website.com/page.php" );
URLConnection conn = (URLConnection) url.openConnection();
conn.setConnectTimeout( 20000 );
conn.setDoOutput( true );
conn.setDoInput( true );
conn.connect();
//3. Call the page and send the parameters to it :
OutputStreamWriter out = new OutputStreamWriter( conn.getOutputStream() );
out.write( params );
out.flush();
out.close();
//4. Get the result :
Object contents = conn.getContent();
InputStream is = (InputStream) contents;
StringBuffer buf = new StringBuffer();
int c;
while( ( c = is.read() ) != -1 ) {
buf.append( (char) c );
}