String getNetData(String connectURL){ String result = ""; //用来取得返回的String; //发送post请求 HttpPost httpRequest = new HttpPost(connectURL); //Post运作传送变数必须用NameValuePair[]阵列储存 try { //发出HTTP请求 Log.d("请求连接", "在发送请求"); List params = new ArrayList(); params.add(new BasicNameValuePair("start", "123321"));//post请求(必须有,数据自定义) //params.add(new BasicNameValuePair("end", end+""));//可添加多个Post请求码,php中按键值对获取 httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); //取得HTTP response HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); //若状态码为200则请求成功,取到返回数据 Log.d("连接值", String.valueOf(httpResponse.getStatusLine().getStatusCode())); if (httpResponse.getStatusLine().getStatusCode() == 200) { //取出字符串 Log.d(&#
android 获取网络数据(超简单,直接调用)
最新推荐文章于 2024-04-28 18:30:27 发布