http中get请求
来源:互联网 发布:mysql 默认排序 编辑:程序博客网 时间:2024/06/06 10:57
package com.gjf.httpgettest;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
String result;
Handler handler = new Handler() {
/**
* Subclasses must implement this to receive messages.
*
* @param msg
*/
@Override
public void handleMessage(Message msg) {
if (msg.what==0x123){
TextView textView = (TextView) findViewById(R.id.tx);
textView.setText(result);}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread() {
//采用get方式访问J2EE服务器
String strUrl = "http://192.168.0.2:8080/HTTPGetTest/GetServlet?param=23333333";
URL url = null;
public void run() {
try
{
url = new URL(strUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream());
BufferedReader buff = new BufferedReader(inputStreamReader);
result = "";
String readLine = null;
while ((readLine = buff.readLine()) != null) {
result += readLine;
}
inputStreamReader.close();
httpURLConnection.disconnect();
handler.sendEmptyMessage(0x123);
} catch (
Exception e
)
{
e.printStackTrace();
}
}
;
}.start();
}
}
这是GET安卓端的代码
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
String result;
Handler handler = new Handler() {
/**
* Subclasses must implement this to receive messages.
*
* @param msg
*/
@Override
public void handleMessage(Message msg) {
if (msg.what==0x123){
TextView textView = (TextView) findViewById(R.id.tx);
textView.setText(result);}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread() {
//采用get方式访问J2EE服务器
String strUrl = "http://192.168.0.2:8080/HTTPGetTest/GetServlet?param=23333333";
URL url = null;
public void run() {
try
{
url = new URL(strUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream());
BufferedReader buff = new BufferedReader(inputStreamReader);
result = "";
String readLine = null;
while ((readLine = buff.readLine()) != null) {
result += readLine;
}
inputStreamReader.close();
httpURLConnection.disconnect();
handler.sendEmptyMessage(0x123);
} catch (
Exception e
)
{
e.printStackTrace();
}
}
;
}.start();
}
}
这是GET安卓端的代码
阅读全文
0 0
- http中get请求
- Http中Get/Post请求区别
- Http中Get/Post请求区别
- Http中Get/Post请求区别
- HTTP中GET和POST请求区别
- Java中发送Http请求Get、Post
- http中get和post请求差别
- http中get和post请求
- Http中Get/Post请求区别
- Android中HTTP Post和Get请求
- 通过Socket实现Http中Get请求
- Http中get和post请求
- Node.js中http 接收get请求、接收post请求、发送get请求、发送post请求
- 关于http请求中get\post请求参数的限制
- HTTP中POST请求与GET请求的区别
- HTTP中GET请求和POST请求的区别
- http协议中,get请求和post请求的区别
- wireshark中HTTP请求get对应HTTP OK
- Mockplus是如何节省你的原型时间的?
- Nginx优化参数
- nginx搭建干活
- HDU6055 Regular polygon(2017多校第二场)
- LeetCode---203. Remove Linked List Elements
- http中get请求
- 提供3D虚拟内容与场景套件 使用SceneKit为您的AR体验添加逼真的三维对象
- 页面调用方法弹出企业QQ联系客服的方法,可以直接复制过去使用
- Struts2——常用标签(数据回显)
- JAVA中的符号引用
- Android 框架炼成 教你如何写组件间通信框架EventBus
- eclipse启动项目出现的问题
- html超级简单实现点赞(收藏)和取消赞效果
- java中string和int互相转化