| | |
| | | |
| | | /** |
| | | * post formData |
| | | * |
| | | * @param url |
| | | * @param map |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @SuppressWarnings("resource") |
| | | public static ResponseDto postFormData(String url, Map<String, Object> map) throws Exception { |
| | | log.info("---------接口请求地址:" +url+ "----------参数:" + JSON.toJSONString(map) +"---------"); |
| | | public static ResponseDto postFormData(String url, Map<String, Object> map) throws Exception { |
| | | log.info("---------接口请求地址:" + url + "----------参数:" + JSON.toJSONString(map) + "---------"); |
| | | BufferedReader in = null; |
| | | URL urls = new URL(url); |
| | | HttpURLConnection connection = null; |
| | |
| | | connection.setConnectTimeout(20000); |
| | | connection.setReadTimeout(30000); |
| | | connection.setRequestMethod("POST"); |
| | | if(StringUtils.isNotEmpty(JSESSIONID)){ |
| | | if (StringUtils.isNotEmpty(JSESSIONID)) { |
| | | // connection.setRequestProperty("Cookie", "JSESSIONID="+JSESSIONID); |
| | | // connection.setRequestProperty(" Set-Cookies", JSESSIONID); |
| | | connection.setRequestProperty("Cookie", "JSESSIONID="+JSESSIONID); |
| | | connection.setRequestProperty("Cookie", "JSESSIONID=" + JSESSIONID); |
| | | } |
| | | map.remove("JSESSIONID"); |
| | | |
| | |
| | | // System.out.println(buffer.toString()); |
| | | outputStream.write(buffer.toString().getBytes()); |
| | | File file = (File) entry.getValue(); |
| | | DataInputStream ins = new DataInputStream(new FileInputStream(file)); |
| | | DataInputStream ins = new DataInputStream(new FileInputStream(file)); |
| | | int bytes = 0; |
| | | byte[] bufferOut = new byte[1024]; |
| | | while ((bytes = ins.read(bufferOut)) != -1) { |
| | |
| | | while ((line = in.readLine()) != null) { |
| | | rs += line; |
| | | } |
| | | }else{ |
| | | } else { |
| | | log.error("http状态:" + connection.getResponseCode()); |
| | | log.error("http消息:" + connection.getResponseMessage()); |
| | | } |
| | |
| | | String serverCookies = connection.getHeaderField("Set-Cookie"); |
| | | log.info("serverCookies:" + serverCookies); |
| | | |
| | | if(serverCookies != null) { |
| | | if (serverCookies != null) { |
| | | |
| | | String[] cookies = serverCookies.split(";"); |
| | | |
| | |
| | | |
| | | } catch (Exception e) { |
| | | System.out.println("发生异常"); |
| | | log.error(e.getMessage(),e); |
| | | log.error(e.getMessage(), e); |
| | | rs = null; |
| | | return new ResponseDto(99,e.getMessage()); |
| | | return new ResponseDto(99, e.getMessage()); |
| | | } |
| | | log.info("---------接口返回:" + rs +"---------"); |
| | | responseDto = JSON.parseObject(rs,ResponseDto.class); |
| | | if(responseDto == null ) return new ResponseDto(99,"接口请求发生未知错误"); |
| | | log.info("---------接口返回:" + rs + "---------"); |
| | | responseDto = JSON.parseObject(rs, ResponseDto.class); |
| | | if (responseDto == null) return new ResponseDto(99, "接口请求发生未知错误"); |
| | | responseDto.setJSESSIONID(JSESSIONID); |
| | | return responseDto; |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | if (in != null){ |
| | | if (in != null) { |
| | | in.close(); |
| | | } |
| | | } catch (Exception e) { |