`
- 浏览:
17605 次
- 性别:
- 来自:
北京
-
Android用WAMPSERVER HttpClient 实现Get请求
-
package com.yarin.android.Examples_08_02;
-
-
import java.io.IOException;
-
import org.apache.http.HttpResponse;
-
import org.apache.http.HttpStatus;
-
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.util.EntityUtils;
-
import android.app.Activity;
-
import android.content.Intent;
-
import android.os.Bundle;
-
import android.view.View;
-
import android.widget.Button;
-
import android.widget.TextView;
-
-
public class Activity02 extends Activity {
-
/** Called when the activity is first created. */
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.http);
-
TextView mTextView = (TextView) this.findViewById(R.id.TextView_HTTP);
-
// http地址
-
String httpUrl = "http://192.168.1.9:8080/linelabel.php"; // 定义需要获取的内容来源地址
-
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());
-
mTextView.setText(strResult);
-
} else {
-
mTextView.setText("请求错误!");
-
}
-
} catch (ClientProtocolException e) {
-
mTextView.setText(e.getMessage().toString());
-
} catch (IOException e) {
-
mTextView.setText(e.getMessage().toString());
-
} catch (Exception e) {
-
mTextView.setText(e.getMessage().toString());
-
}
-
-
// 设置按键事件监听
-
Button button_Back = (Button) findViewById(R.id.Button_Back);
-
/* 监听button的事件信息 */
-
button_Back.setOnClickListener(new Button.OnClickListener() {
-
public void onClick(View v) {
-
/* 新建一个Intent对象 */
-
Intent intent = new Intent();
-
/* 指定intent要启动的类 */
-
intent.setClass(Activity02.this, Activity01.class);
-
/* 启动一个新的Activity */
-
startActivity(intent);
-
/* 关闭当前的Activity */
-
Activity02.this.finish();
-
}
-
});
-
}
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
android 通过WampServer集成环境通过php+mysql实现注册登录功能,中文不乱码,参考别人的代码自己写的,大家一起交流。
wampserver
wampserver3_x64位 集成环境版本如下: apache2.4.35 mysql5.7.23 php5.6.38、php7.0.32、php7.4.22、php8.0.10
wampserver,wampserver插件
1.直接双击下载的安装包进行,安装后在浏览器打开localhost,出现如下图所示界面即为安装成功并且正常运行。 2.选择语言 ...改好之后要退出Wamp,重新打开启动配置才会生效,我开始直接重启服务就能用。
Android 部署在 Wampserver 所需要的工具和代码,包括: 1. AndroidPushNotificationsDemo (移动端Android 代码) 2. ia92 (测试工具) 3. rsmb_1.2.0 (测试工具) 4. send_mqtt (PHP 代码)
WampServer 安装与使用过程 很详细 PDF电子书格式
wampserver2.0集成环境安装使用简易手册
WampServer是一款由法国人开发的Apache Web服务器、PHP解释器以及MySQL数据库的整合软件包。使用简单,方便快捷。
wampserver3.1.0_x64下载地址wampserver3.1.0_x64下载地址wampserver3.1.0_x64下载地址wampserver3.1.0_x64下载地址
用WampServer2.0搭建Discuz!
01-WampServer2.0c
欢迎使用WampServer。 WampServer=Windows+Apache+MySQL+PHP MySQL用户名:root MySQL密 码:(无密码。) WampServer 1.0 for Windows PE/XP/2003/Vista/2008/7/8基本参数如下: Apache 2.2.22(稳定版) ...
WampServer64,用PHPstorm的时候用到的WampServer64,欢迎下载使用。
PHP与WampServer中MYsql连接使用实现页面前端的登陆验证
php+mysql开发 WampServer2.0c