android http 连接通信
来源:互联网 发布:手语软件下载 编辑:程序博客网 时间:2024/05/29 15:52
一共有三个文件,JAVA,MAIN.XML,AndroidManifest.xml
JAVA文件:
JAVA文件:
package Android_https.com;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Android_httpsActivity extends Activity { privateButton sendbutton = null; privateHttpResponse httpResponse = null; privateHttpEntity httpEntity = null; @Override public voidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sendbutton = (Button)findViewById(R.id.sendbutton); sendbutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { HttpGet httpget = newHttpGet("http://localhost/"); HttpClient httpClient = newDefaultHttpClient(); InputStream inputStream = null; try { httpResponse = httpClient.execute(httpget); httpEntity = httpResponse.getEntity(); inputStream = httpEntity.getContent(); BufferedReader reader = new BufferedReader(newInputStreamReader(inputStream)); String result = "" ; String line = ""; while ((line = reader.readLine()) != null){ result = result + line; } System.out.println(result); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("有错误!!!"); e.printStackTrace(); } } }); }}
<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/sendbutton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="简单发送请求,并回得报文" /></LinearLayout>
<?xml version="1.0"encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android" package="Android_https.com" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="3"/> <uses-permissionandroid:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".Android_httpsActivity" > <intent-filter > <action android:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application></manifest>
- android http 连接通信
- android http通信方式连接网络
- android http通信方式连接网络
- android http通信方式连接网络
- android HTTP通信方式连接网络
- Http连接通信过程
- android-async-http(http通信)
- 《Android开发卷——HTTP网络通信,HTTP网络连接》
- Android中HTTP通信
- android:HTTP通信
- android--http通信示例
- Android中HTTP通信
- Android Http通信
- Android http 通信
- Android HTTP通信
- android http通信
- Android中的Http通信
- Android中的Http通信
- 建网站
- LINUX Ubuntu 11.04 tomcat 7.0
- 基于鼠标点击跟踪的用户点击行为分…
- UltraISO(软碟通)制作安装Ubuntu
- C#中引用类型和值类型分别有哪些
- android http 连接通信
- Acegi的标签库authzauthorize
- LINUX ubuntu JAVA 切换JDK版本
- ubuntu 常用命令 常见问题 集
- ubuntu grub 手动进入系统
- ubuntu 虚拟XP chm文件用不了
- 页面部分显示与显隐控制
- 数据类型、变量、数组类
- 类型转换与强制转换