android http get

来源:互联网 发布:阿里云域名空间 编辑:程序博客网 时间:2024/04/28 19:02

主要代码:

public void selfDestruct(View view) {     // KabloeySystem.out.printf("haha this is a button event!\n");Log.v(TAG, "index=" + 2);String htpget="http://localme.sinaapp.com/insert_point.php?" +"longitude=0&latitude=112.297675";HttpGet httpRequest=new HttpGet (htpget); try           {             /*发出HTTP request*/            HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);             /*若状态码为200 ok*/            if(httpResponse.getStatusLine().getStatusCode() == 200)              {         Log.v(TAG, "http get ok" );          }             else             {             Log.v(TAG, "http get error" );          }           }           catch (ClientProtocolException e)           {             Log.v(TAG, "http get IOException1" );        } catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace(); Log.v(TAG, "http get IOException2" );}           }



权限:

<uses-permission android:name="android.permission.INTERNET" />




简单代码上传在:

http://download.csdn.net/detail/xyyangkun/5326560

原创粉丝点击