我正在使用JSON对象发送HTTP Post请求。我的程序在IDE中运行得非常好,但是当我从桌面上的JAR文件运行它时,它会卡住。
代码
if ((act.getSource() == sendAlertButton)) {
JOptionPane.showMessageDialog(null, "Inside send alert button handler");
//Creating JSON
JSONObject mainObj = new JSONObject();
JOptionPane.showMessageDialog(null, "Created main object");
//Handles access token
mainObj.put("access_token", *access token*);
JOptionPane.showMessageDialog(null, "Created access token");
//Handles file format
mainObj.put("format", "json");
JOptionPane.showMessageDialog(null, "Created format");
//Handles alarm
JSONObject alarmObj = new JSONObject();
//Fill alarmObj
JOptionPane.showMessageDialog(null, "Created alarm fields");
//Handles event
JSONObject eventObj = new JSONObject();
//Fill eventObj
JOptionPane.showMessageDialog(null, "Created event fields");
JOptionPane.showMessageDialog(null, "JSON Object created successfully");
//Send Post
Map<String, String> headerMap = new HashMap<String, String>();
String bodyStr = mainObj.toString();
InputStream body = new ByteArrayInputStream(bodyStr.getBytes());
//System.out.println("Sending Post");
post(*IP address*, headerMap, body);
JOptionPane.showMessageDialog(null, "Alert sent successfully!");
}
它永远不会输出&#34;创建的主要对象&#34; ,所以我知道它会卡在JSONObject mainObj = new JSONObject();
上
线。任何想法为什么只有当我在IDE之外运行它时才会发生这种情况?