| | |
| | | } |
| | | } |
| | | |
| | | public String doGet(String pid){ |
| | | public String doGet(String pid) { |
| | | // 从配置中获取 API URL,并拼接 key |
| | | String apiUrl = PropertiesUtil.getProperty("JS_IN_HTTP_URL") + "stock?key=" + PropertiesUtil.getProperty("JS_IN_KEY"); |
| | | String result = null; |
| | | try { |
| | | Thread.sleep(3000); |
| | | URL url = new URL(apiUrl); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | |
| | | // 设置请求方法为 POST |
| | | connection.setRequestMethod("POST"); |
| | | // 设置请求头 |
| | | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | | connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); |
| | | connection.setDoOutput(true); // 允许向连接输出 |
| | | |
| | | // 构建 POST 数据 |