- public String resposeString(String urlStr){
- String result = "";
- try
- {
- URL url = new URL(urlStr);
- HttpURLConnection httpURLConnection = null;
- httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);//上传数据
- httpURLConnection.setConnectTimeout(15000);
- httpURLConnection.setReadTimeout(15000);
- InputStream inputStream = httpURLConnection.getInputStream();//获取返回的数据流
- InputStreamReader isr = new InputStreamReader(inputStream, "gbk");//一定要在这个地方才不会乱码(utf-8,gb2312)
- BufferedReader br = new BufferedReader(isr);//利用BufferedReader将流转为String
- String temp;
- while((temp = br.readLine()) != null)
- {
- result = result + temp;
- }
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- return result;
- }
转载网址:http://blog.csdn.net/qq_36226579/article/details/70171972