Znn3bq.jpeg
±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 4235  |  »Ø¸´: 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 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ÉúÎïÒ½Ò©µ÷¼Á£üSCIÖпÆÔºÈýÇøÒ»×÷+¶àÏî¿ÆÑгɹû +8 likangxing 2026-04-07 11/550 2026-04-08 00:02 by lys0704
[¿¼ÑÐ] Ò»Ö¾Ô¸211£¬»¯Ñ§Ñ§Ë¶£¬310·Ö£¬±¾¿ÆÖصãË«·Ç£¬Çóµ÷¼Á +19 ŬÁ¦·Ü¶·112 2026-04-07 20/1000 2026-04-07 23:12 by JourneyLucky
[¿¼ÑÐ] 316Çóµ÷¼Á +4 15318418673 2026-04-07 4/200 2026-04-07 22:12 by hemengdong
[¿¼ÑÐ] Ò»Ö¾Ô¸Ö£ÖÝ´óѧ²ÄÁÏÓ뻯¹¤085600£¬Çóµ÷¼Á +34 ³ÔµÄ²»ÉÙ 2026-04-02 34/1700 2026-04-07 20:01 by lrll?l
[¿¼ÑÐ] 283Çóµ÷¼Á +18 A child 2026-04-04 18/900 2026-04-07 12:30 by 1018329917
[¿¼ÑÐ] 286Çóµ÷¼Á +20 Faune 2026-04-06 20/1000 2026-04-07 11:33 by Ê«Óë×ÔÓÉ
[¿¼ÑÐ] 333Çóµ÷¼Á +6 ºÏ³ËÑîϰϦ 2026-04-06 6/300 2026-04-07 09:44 by Öí»á·É
[¿¼ÑÐ] 085100½¨Öþѧ ѰÇó¿çרҵµ÷¼Á Ò»Ö¾Ô¸ÄÏ´ó294·Ö У¼¶Ê¡¼¶¹ú¼Ò¼¶½±ÏîÈô¸É ̤ʵ¿Ï¸É +3 1021075758 2026-04-06 4/200 2026-04-07 09:23 by À¶ÔÆË¼Óê
[¿¼ÑÐ] 346·ÖµÄÉúÎïÓëÒ½Ò©08600Çóµ÷¼Á +6 ³£ÓêÑôÉϰ¶ 2026-04-05 7/350 2026-04-06 12:36 by lys0704
[¿¼ÑÐ] Çóµ÷¼Á +7 ÕÅ.1 2026-04-05 7/350 2026-04-05 20:40 by à£à£à£0119
[¿¼ÑÐ] Ò»Ö¾Ô¸µç×ӿƼ¼´óѧ085600²ÄÁÏÓ뻯¹¤ 329·ÖÇóµ÷¼Á +10 Naiko 2026-04-04 10/500 2026-04-05 09:40 by sam3303
[¿¼ÑÐ] 277Çóµ÷¼Á +4 12A3 2026-04-02 5/250 2026-04-04 20:28 by À¶ÔÆË¼Óê
[¿¼ÑÐ] Ò»Ö¾Ô¸ÄÏÅ©090401£¬268£¬Çóµ÷¼Á +5 һľÄñÈ» 2026-04-04 5/250 2026-04-04 17:07 by babysonlkd
[¿¼ÑÐ] Ò»Ö¾Ô¸¶«±±´óѧ085901ÍÁľר˶345Çóµ÷¼Á +3 zxt11111 2026-04-04 3/150 2026-04-04 14:21 by ÍÁľ˶ʿÕÐÉú
[¿¼ÑÐ] 085601Ò»Ö¾Ô¸±±Àí325·ÖÇóµ÷¼Á +6 ÕÒµ÷¼Á£¬£¬ 2026-04-02 6/300 2026-04-03 22:20 by –¹Æ?
[¿¼ÑÐ] 293Çóµ÷¼Á +5 ĩδmm 2026-04-02 6/300 2026-04-03 15:20 by Íõ±£½Ü33
[¿¼ÑÐ] 285Çóµ÷¼Á +7 AZMK 2026-04-02 9/450 2026-04-03 11:12 by wanwan00
[¿¼ÑÐ] 302Çóµ÷¼Á +9 zyxÉϰ¶£¡ 2026-04-02 9/450 2026-04-02 23:07 by Âí¶ù¿ì¿ìµØÅÜ
[¿¼ÑÐ] 346Çóµ÷¼Á +5 Ö£³ÏÀÖ 2026-04-02 5/250 2026-04-02 16:38 by SZW_UJN
[¿¼ÑÐ] ½­ËտƼ¼´óѧÕвÄÁÏÑо¿Éú +4 Su032713. 2026-04-01 5/250 2026-04-01 22:03 by cccchenso
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û