²é¿´: 4232  |  »Ø¸´: 0

suzikid

гæ (³õÈëÎÄ̳)

[ÇóÖú] httpgetÉèÖÃÍøÂ糬ʱʱ¼ä

package com.example.httpgetpost;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;


import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class HttpGetPost extends Activity {
    private Button httpGetButton;
    private URL url=null;

   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
                try {
                        url = new URL("http://www.baidu.com/";
                } catch (MalformedURLException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }  
        httpGetButton = (Button)findViewById(R.id.httpget);
        //httpPostButton = (Button)findViewById(R.id.httppost);
        httpGetButton.setOnClickListener(new OnClickListener(){
                public void onClick(View arg0) {
                                HttpGet httpget = new HttpGet( url.toString() );  
                                InputStream in=null;
                        HttpClient client = new DefaultHttpClient();  
                        HttpParams params = client.getParams();
                        HttpConnectionParams.setConnectionTimeout(params, 30000);
                                  
                            try {
                                        HttpResponse response = client.execute( httpget );
                                        HttpEntity httpentity = response.getEntity();
                                        in=httpentity.getContent();
                                        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                                        String line="";
                                        String result = "";
                                        while((line=reader.readLine())!=null)
                                        {
                                                result = result+line;
                                        }
                                        System.out.println("===========";
                                        System.out.println(result);
                                } catch (ClientProtocolException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } finally{
                                        if(in!=null)
                                                try {
                                                        in.close();
                                                } catch (IOException e) {
                                                        // TODO Auto-generated catch block
                                                        e.printStackTrace();
                                                }
                                }
                        }
        });
    }
}
XML
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    androidrientation="vertical" >
              android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mTextView"
        android:text="@string/hello_world"
        />
              android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/httpget"
        android:text="@string/httpget"/>
                android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/httppost"
        android:text="@string/httppost"/>





ΪºÎÔÚ2.3.1ÉÏ¿ÉÒÔÔËÐУ¬µ«ÊÇÔÚ4.0.3ÉÏÈ´²»¿ÉÒÔ£¬¶øÇÒhttpget¿ÉÒÔÓÃÍøÂçurlÂð£¿ÎªÊ²Ã´ºÃÏñÖ»¿ÉÒÔÓñ¾µØurl£¬»»³ÉÍøÂçurl¾ÍÁ¬½Ó²»ÉÏ
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ÖÇÄÜ»úÆ÷ÈË

Robot (super robot)

ÎÒÃǶ¼°®Ð¡Ä¾³æ

Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ suzikid µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 085700×ÊÔ´Óë»·¾³308Çóµ÷¼Á +3 īīĮ 2026-03-18 3/150 2026-03-18 22:35 by bingxueer79
[¿¼ÑÐ] 328Çóµ÷¼Á£¬Ó¢ÓïÁù¼¶551£¬ÓпÆÑо­Àú +3 ÉúÎ﹤³Ìµ÷¼Á 2026-03-17 7/350 2026-03-18 20:41 by Wangjingyue
[¿¼ÑÐ] 0703»¯Ñ§ 305Çóµ÷¼Á +3 FY_yy 2026-03-14 3/150 2026-03-18 19:40 by macy2011
[¿¼ÑÐ] Ò»Ö¾Ô¸Öйúº£Ñó´óѧ£¬ÉúÎïѧ£¬301·Ö£¬Çóµ÷¼Á +4 1ËïÎò¿Õ 2026-03-17 4/200 2026-03-18 17:59 by fivewind
[¿¼ÑÐ] 26µ÷¼Á/²ÄÁÏ/Ó¢Ò»Êý¶þ/×Ü·Ö289/ÒѹýAÇøÏß +7 ²½´¨¿á×Ï123 2026-03-13 7/350 2026-03-18 17:12 by ¾¡Ë´Ò¢1
[¿¼ÑÐ] 314Çóµ÷¼Á +8 ÎÞи¿É»÷µÄ¾ÞÈË 2026-03-12 8/400 2026-03-18 14:50 by haxia
[¿¼ÑÐ] 302Çóµ÷¼Á +10 ºôºôºô¡£¡£¡£¡£ 2026-03-17 10/500 2026-03-18 12:45 by Linda Hu
[¿¼ÑÐ] 288Çóµ÷¼Á£¬Ò»Ö¾Ô¸»ªÄÏÀí¹¤´óѧ071005 +4 ioodiiij 2026-03-17 4/200 2026-03-18 12:36 by Linda Hu
[¿¼ÑÐ] Áº³ÉΰÀÏʦ¿ÎÌâ×é»¶Ó­ÄãµÄ¼ÓÈë +8 һѼѼӴ 2026-03-14 10/500 2026-03-17 15:07 by һѼѼӴ
[»ù½ðÉêÇë] ½ñÄêµÄ¹ú»ù½ðÊÇ´ò·ÖÖÆÂ𣿠50+3 zhanghaozhu 2026-03-14 3/150 2026-03-16 17:07 by ±±¾©À³ÒðÈóÉ«
[¿¼ÑÐ] 085600µ÷¼Á +5 ÑúÑú123sun 2026-03-12 6/300 2026-03-16 15:58 by ÑúÑú123sun
[¿¼ÑÐ] 0703 ÎïÀí»¯Ñ§µ÷¼Á +3 ÎÒ¿ÉÒÔÉϰ¶µÄ¶Ô 2026-03-13 5/250 2026-03-16 10:50 by ÎÒ¿ÉÒÔÉϰ¶µÄ¶ÔÂ
[¿¼ÑÐ] 326Çóµ÷¼Á +3 mlpqaz03 2026-03-15 3/150 2026-03-16 07:33 by Iveryant
[¿¼ÑÐ] 070305Çóµ÷¼Á +3 mlpqaz03 2026-03-14 4/200 2026-03-15 11:04 by peike
[¿¼ÑÐ] 288Çóµ÷¼Á +4 Ææµã0314 2026-03-14 4/200 2026-03-14 23:04 by JourneyLucky
[¿¼ÑÐ] ѧ˶285Çóµ÷¼Á +13 Wisjxn 2026-03-12 46/2300 2026-03-14 10:33 by JourneyLucky
[¿¼ÑÐ] Çóµ÷¼Á +5 Ò»¶¨ÓÐѧÉÏ- 2026-03-12 5/250 2026-03-13 18:31 by ms629
[¿¼ÑÐ] 289Çóµ÷¼Á +3 ÀîÕþÓ¨ 2026-03-12 3/150 2026-03-13 11:02 by Çóµ÷¼Ázz
[¿¼ÑÐ] 321Çóµ÷¼Á£¨Ê³Æ·/ר˶£© +3 xc321 2026-03-12 6/300 2026-03-13 08:45 by xc321
[¿¼ÑÐ] 333Çóµ÷¼Á +3 152697 2026-03-12 4/200 2026-03-13 07:08 by Iveryant
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û