java发送http请求

来源:互联网 发布:智能对话机器人软件 编辑:程序博客网 时间:2024/05/31 19:10
<span style="font-size:14px;">URL url = new URL("https://openapi.baidu.com/rest/2.0/iplib/query?access_token=30.631bf9d9173a40de6e6402eb756710b8.2592000.1390149393.3440595551-1735619");URLConnection connection = url.openConnection();  connection.setDoOutput(true);  OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");out.write("ip=222.36.223.19");  out.flush();out.close();  // 一旦发送成功,用以下方法就可以得到服务器的回应:String sCurrentLine;String sTotalString;sCurrentLine = "";sTotalString = "";InputStream l_urlStream;l_urlStream = connection.getInputStream();  BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));while ((sCurrentLine = l_reader.readLine()) != null) {sTotalString += sCurrentLine ; }</span>


0 0
原创粉丝点击