WEB开发网
开发学院手机开发Android 开发 Android HttpConnect 阅读

Android HttpConnect

 2010-10-19 20:17:34 来源:WEB开发网   
核心提示:89. Pattern p = Pattern.compile(strPattern);90. Matcher m = p.matcher(strTarget);91.92. if (m.find()) {93. return strTarget.replaceAll(strFrom, strTo);94. } els

89. Pattern p = Pattern.compile(strPattern);

90. Matcher m = p.matcher(strTarget);

91.

92. if (m.find()) {

93. return strTarget.replaceAll(strFrom, strTo);

94. } else {

95. return strTarget;

96. }

97. }

98.

99. }

package my.android.hc; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class HttpConnect extends Activity { private Button mb1,mb2; private TextView mtv1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mb1 = (Button) findViewById(R.id.b1_id); mb2 = (Button) findViewById(R.id.b2_id); mtv1 = (TextView) findViewById(R.id.tv1_id); mb1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String uriAPI = "http://www.dubblogs.cc:8751/android/test/api/post/index.php"; HttpPost httpRequest = new HttpPost(uriAPI); List < NameValuePair> params = new ArrayList< NameValuePair>(); params.add(new BasicNameValuePair("str", "i am post string")); try { httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); if

上一页  1 2 3 4 5 6  下一页

Tags:Android HttpConnect

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接