java发送http请求

<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>


你可能感兴趣的:(java发送http请求)