我有当用户在其卡上的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