代码大概如下
private void getMethod()
{
String httpUrl= “http://wdou.cn/luo/a.php”;
// HttpGet连接对象
HttpGet httpRequest = new HttpGet(httpUrl);
try {
// 取得HttpClient对象
HttpClient httpclient = new DefaultHttpClient();
// 请求HttpClient,取得HttpResponse
HttpResponse httpResponse = httpclient.execute(httpRequest);
// 请求成功
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 取得返回的字符串
String strResult = EntityUtils.toString(httpResponse
.getEntity());
textview1.setText(strResult);
} else {
textview1.setText(“请求错误!”);
}
} catch (Exception e) {
e.printStackTrace();
}
}
使用php实现,只需要file_get_contents(“http://xxx.com/a.php”)
实在是反人类啊。。
一开始一直报错,就是throw exceptions。一大堆也看不懂,应该是function的位置不对,好像是忘记了this的原因。activity的代码:
public class LuoActivity extends Activity
{
/** Called when the activity is first created. */
private TextView textview1;
private Button button1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textview1=(TextView)findViewById(R.id.textview1);
textview1.setText(“caooooooo”);
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new Button.OnClickListener()
{
public void onClick (View v)
{
this.getMethod();
}
}
需要记住的类好多,不知道有什么好方法记住。

