HttpURLConnection
来源:互联网 发布:淘宝 自带 库存管理 编辑:程序博客网 时间:2024/05/24 00:31
private void getid(){ new Thread(){ @Override public void run() { try { String data="userPhone="+s_phone+"&userPassword="+s_pass; URL url=new URL(urla); HttpURLConnection openConnection= (HttpURLConnection) url.openConnection(); openConnection.setRequestMethod("POST"); openConnection.setConnectTimeout(5000); openConnection.setReadTimeout(5000); openConnection.setDoOutput(true);// 准备写出 openConnection.getOutputStream().write(data.getBytes());// 写出数据 openConnection.connect(); if (openConnection.getResponseCode()==200) { InputStream in = openConnection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8")); String str; StringBuffer sb = new StringBuffer(); while ((str = br.readLine()) != null) { sb.append(str); } Message message = new Message(); message.what=0; message.obj=sb.toString(); handler.sendMessage(message); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start();}
private void getid() { new Thread() { @Override public void run() { try { URL url = new URL(urla); //URL链接对象,通过URL对象打开一个connection链接对像 HttpURLConnection openConnection = (HttpURLConnection) url.openConnection(); openConnection.setRequestProperty("Accept-Charset", "GBK"); openConnection.setRequestProperty("contentType", "GBK"); openConnection.setConnectTimeout(5 * 1000); openConnection.setRequestMethod("GET"); openConnection.connect(); int flag = openConnection.getResponseCode(); if (flag == 200) { //调用urlConnection.getInputStream得到本次请求所返回的结果流 InputStream inStream = openConnection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "GBK")); String readerli; StringBuffer buffer = new StringBuffer(); while ((readerli = in.readLine()) != null) { buffer.append(readerli); } Message message = new Message(); message.what = 0; message.obj = buffer.toString(); handler.sendMessage(message); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start();}
0 0
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- httpurlconnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- HttpURLconnection
- HttpURLConnection
- HttpURLConnection
- HttpURLConnection
- httpurlconnection
- 团队开发
- [leetcode] 116. Populating Next Right Pointers in Each Node
- 【HDU 杭电 5256 序列变换】
- centos 下搭建VPN服务器 pptpd
- java新特性之for循环最全用法集锦
- HttpURLConnection
- 常用软件大集合
- android布局适配
- Android下拉状态栏快捷开关的添加
- Red Hat 6.5配置 Centos 6.5 本地yum源
- 高级IO
- 线程安全与锁优化
- little/big endian
- vxworks---多任务(1)