android:CMWAP GPRS 连接

package android.HttpTest;

import java.net.URL;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HttpTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView tv = new TextView(this);
        String myString = "";
        try{
        	HttpHost proxy = new HttpHost("10.0.0.172", 80, "http");
        	HttpHost target = new HttpHost("http://www.xxxxxx.com", 80, "http");
        	DefaultHttpClient httpclient = new DefaultHttpClient();

        	httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        	HttpGet req = new HttpGet("/");

        	System.out.println("executing request to " + target + " via " + proxy);
        	HttpResponse rsp = httpclient.execute(target, req);
        	HttpEntity entity = rsp.getEntity();
        	System.out.println("----------------------------------------");
        	System.out.println(rsp.getStatusLine());
        	Header[] headers = rsp.getAllHeaders();
        	
        	for (int i = 0; i<headers.length; i++) {
        		System.out.println(headers[i]);             		
        	}
        	myString = rsp.getStatusLine().toString();//headers.toString();
        	
        	System.out.println("----------------------------------------");
        	if (entity != null) {
        		System.out.println(EntityUtils.toString(entity));
        	}
        	httpclient.getConnectionManager().shutdown(); 
        }   
        catch(Exception e)
        {
        	myString = e.getMessage();	
        }
        tv.setText(myString);
        this.setContentView(tv);
    } 
}

你可能感兴趣的:(android:CMWAP GPRS 连接)