admin 管理员组

文章数量: 887609


2024年1月10日发(作者:go语言入门开源项目)

t(reqUrl, "请求地址为空"); t(params, "请求数据为空"); } catch (Exception e) { throw new Exception("发送请求参数为空:" + sage(), e); } String request = params ;//发送服务端数据 HttpURLConnection httpConnection = null; try { httpConnection = (HttpURLConnection) new URL(reqUrl) .openConnection(); uestMethod("POST"); utput(true); nput(true); Caches(false); uestProperty("Connection", "Keep-Alive"); uestProperty("Charset", yName()); uestProperty("Content-Type", "application/json; charset=" + yName()); uestProperty("accept", "application/json"); dTimeout(readTimeSec * 1000);// 设置http连接的读超时,单位是毫秒 nectTimeout(connTimeSec * 1000); // 1、连接 try { t(); } catch (Exception e) { throw new Exception( "服务器连接是失败"); } OutputStream outwritestream = null; // 2、发送数据 try { //n("请求数据:"+request); byte[] writebytes = es(charset); outwritestream = putStream(); (writebytes); (); } catch (Exception e) { throw new Exception( "请求数据发送失败", e); } finally { try { (); } catch (Exception e) { } } return getHttpReturn(httpConnection , charset); } catch (Exception e) { throw new Exception("服务器连接失败:" + sage(), e); } finally { if (httpConnection != null) { nect(); } } }

/** * @param httpConnection

* @return Http连接返回数据转化成字符串 * @throws Exception */ private static String getHttpReturn(HttpURLConnection httpConnection , Charset charset) throws Exception { int responseCode = -1; try {


本文标签: 数据 连接 请求 发送 失败