根据url发送请求,并获取返回的信息

/**
* 请求
* @author shmily
*
*/
public class HttpUtil {
//根据url发送请求,并获取返回的信息
public static String post(String url) {
String sTotalString = null;
try {
URL l_url = new URL(url);
HttpURLConnection l_connection = (HttpURLConnection) l_url.openConnection();
l_connection.connect();
InputStream l_urlStream;
l_urlStream = l_connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
String sCurrentLine = null;
while ((sCurrentLine = l_reader.readLine()) != null)
{
sTotalString += sCurrentLine;
}
} catch (IOException e) {
e.printStackTrace();
}
return sTotalString;
}
}

你可能感兴趣的:(url)