android网络

学习Android的朋友欢迎加入:群 59324839(QQ)

1URL url = new URL("http://www.sohu.com/");

         2HttpURLConnection conn = (HttpURLConnection)url.openConnection();

         3:参数设定;

conn.setRequestMethod("GET");

                   conn.setConnectTimeout(5 * 1000);

设置位图:

         Bitmap  bitmap = BitmapFactory.decodeByArray(byte[],0,length);

         imageView.setImageBitmap(bitmap);

 

 

JSON(org.json)

         JSONArray  json = new JSONArray(String);

         Json.getId(); à>json.getString();à>json.getLong();

                                                                    

网络数据提交:

HttpRequest.sendGetRequest(*******);

S数据编码:URLEncoder.eccode();

 

使用手机上传数据的时候要对数据进行编码:

Conn.setRequestMethod(“POST”);

Conn.setRequestTimeout(1000);

Conn.setDoOutput(ture);//准许对出输出数据

Conn.setRequestProperty(“application/x-www-form-urlencoded”);

Conn.setRequestProperty(“Content-Length”,String.valueOf(entitydata.length)); 

得到服务器路径:

Request.getSession().getServletContext().getRealPath(“/video”);                                  

 

 

Androidjson的处理;

            内置对象JSONArray  array = new JSONArray(String);

            JSONObject item = array.getJSONObject(i);

            Item.get(“key”);                

 

你可能感兴趣的:(android)