zoukankan      html  css  js  c++  java
  • android 网络通讯



    //get方式请求网络数据
    String urlPath="http://192.168.98.112:8080/CloudMusicPlayer/fragment1_1_lv2/json/SongInfo.json"; // String data="SongName=驿动的心&SongAutor=姜育恒"; HttpURLConnection connection=null; try { URL url=new URL(urlPath); connection=(HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setUseCaches(false); connection.setConnectTimeout(10000); connection.setReadTimeout(5000); if(connection.getResponseCode()==200){ InputStream is=connection.getInputStream(); int count=0; StringBuilder sb=new StringBuilder(); while((count=is.read())!=-1){ sb.append((char)count); } if(is!=null){ is.close(); } try { JSONObject jsonObject=new JSONObject(sb.toString()); final String songName = jsonObject.getString("SongName"); final String SongAutor = jsonObject.getString("SongAutor"); Log.v("msg",songName); getActivity().runOnUiThread(new Runnable() { @Override public void run() { head_tv1.setText(songName); head_tv2.setText(SongAutor); } }); } catch (JSONException e) { e.printStackTrace(); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { if(connection!=null){ connection.disconnect(); } }
  • 相关阅读:
    密码
    日历游戏
    最大公约数
    从map到hash
    9、RabbitMQ-集成Spring
    8、RabbitMQ-消息的确认机制(生产者)
    7、RabbitMQ-主题模式
    6、RabbitMQ-路由模式
    5、RabbitMQ-订阅模式 Publish/Subscribe
    4、RabbitMQ-消息应答与消息持久化
  • 原文地址:https://www.cnblogs.com/yzjT-mac/p/5822542.html
Copyright © 2011-2022 走看看