android http请求服务器
2018-01-13 15:32
295 查看
HTTP GET请求是把参数拼接到url中
/**HTTP get请求服务器
*/
public String getData() {
//get的方式提交就是url拼接的方式
String url = "http://192.168.11.6:8080/?name="+123+"&passwork="+123;
try {
URL httpUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();//与服务器建立连接;
conn.setReadTimeout(5000);
//设置请求方式为GET
conn.setRequestMethod("GET");
//把获取的数据不断存放到StringBuffer中;
final StringBuffer sb = new StringBuffer();
//把获取的数据不断存放到StringBuffer中;
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
//只要还没有读取完,就不断读取;
while ((line = reader.readLine()) != null) {
//在StringBuffer中添加;
sb.append(line);
}
String toString = sb.toString();
Log.i(TAG, "----token--->:" + toString);
4000
JSONObject jsonObject = new JSONObject(toString);
String openid = jsonObject.getString("openid").toString().trim();
String access_token = jsonObject.getString("access_token").toString().trim();
// getUserMesg(access_token, openid);
getNetWorkLogin(openid, "111111", adresseMAC);
} catch (ProtocolException e1) {
e1.printStackTrace();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
相关文章推荐
- Android使用HttpUrlConnection请求服务器发送数据详解
- Android连接服务器请求架包之 Async-http-client
- 我的Android进阶之旅------>Android发送GET和POST以及HttpClient发送POST请求给服务器响应
- Android使用httpPost向服务器发送请求的方法
- Android--使用Http向服务器发送请求并取得返回结果,下载图片
- Android Http请求服务器返回505
- Android使用HttpURLConnection和HttpClient请求服务器数据
- android通过httpPost向服务器发送请求
- android使用asynchttp网络请求服务器返回json数据并显示在手机
- Android网络编程之Http请求服务器数据(POST方式)
- [转]android之Apache Http——向服务器发送请求的同时发送参数
- Android网络编程之Http请求服务器数据(GET方式)
- Android Http post 请求传递json 内包含数组 给服务器的实现方式.
- android之Apache Http初使用——向服务器发送请求
- Android开发 httpClient post方法请求tomcat服务器实现注册登陆
- Android使用HttpUrlConnection请求服务器发送数据详解
- Android使用HttpURLConnection进行POST请求,向服务器上传数据
- Android--使用Http向服务器发送请求并取得返回结果,下载图片
- Android网络编程之Http请求服务器数据(POST方式)
- Android 通过httpclient请求web服务器,并解决用户登录session保持