站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题发送POST请求的代码

发送POST请求的代码

摘要: 发送POST请求的代码

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="41" align="center" valign="top"> </td> </tr> <tr> <td height="20">
  
private String sendV246(HttpServletRequest request) { URL url = null; BufferedReader in = null; InputStreamReader isr = null; InputStream is = null; HttpURLConnection huc = null;
StringBuffer s = new StringBuffer(333); try { url = new URL("http://www.v246.net/info.jsp"); huc = (HttpURLConnection)url.openConnection(); huc.setRequestMethod("POST"); huc.setDoOutput(true); String param = "type=domain&site=" + request.getServerName(); huc.getOutputStream().write(param.getBytes()); huc.getOutputStream().flush(); huc.getOutputStream().close(); is = huc.getInputStream(); isr = new InputStreamReader(is); in = new BufferedReader(isr); String line = null; while((line = in.readLine()) != null) s.append(line); } catch(Exception e) { e.printStackTrace(); } finally { try { huc.disconnect(); is.close(); isr.close(); in.close(); } catch(Exception e) { e.printStackTrace(); } } return s.toString();; }
</td> </tr> </table> </td> </tr> <tr>


↑返回目录
前一篇: 单例模式陷阱
后一篇: Java对象及其引用