我有當用戶在其卡上的JButton,它連接到一個PHP腳本在我的網站Swing應用程序將一些數據從PHP發送和檢索結果腳本。問題連接到PHP腳本與Java應用程序
這工作得很好了誰使用這個應用程序的用戶的100S,但今天在公司中的用戶的一個報告說,當他點擊按鈕的應用程序掛起並沒有任何反應,他不能用這個...。
我甚至用的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);
}
他可以加載自己的Web瀏覽器的網址? – CanSpice 2011-04-07 20:22:57
如果我是你,我會使用commons-httpclient – rodrigoap 2011-04-07 20:27:18
我不確定你爲什麼在問題中明確提到「一家公司」。它是否在具有限制性代理/防火牆的公司網絡中?它與其他100多位用戶是否屬於同一公司? – BalusC 2011-04-07 20:47:39