Android 使用HttpGet进行登录
2016-04-22 22:00
375 查看
public class HttpActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final EditText editText = new EditText(this); Button button = new Button(this); button.setText("登录"); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { httpGet(editText); } }); } private void httpGet(final EditText editText) { try { HttpClient httpClient = new DefaultHttpClient(); String username = "tom"; String password = "123"; String uri = "http://www.baidu.com?username=" + URLEncoder.encode(username,"utf-8") + "&password="+ URLEncoder.encode(password,"utf-8"); HttpGet httpGet = new HttpGet(uri); HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200) { InputStream inputStream = response.getEntity().getContent(); String result = NetUtils.parseStream(inputStream); editText.setText(result); } } catch (Exception e) { e.printStackTrace(); } } }
相关文章推荐
- Android 读取网络数据
- (经典)tcp粘包分析
- 关于TCP的问题总结
- 网络爬虫
- TCP/IP、Http、Socket的区别
- 网络请求
- 神经网络编程
- HNOI2016 网络
- 实现基于TCP/IP协议的简单Client/Server程序
- HTTP协议--cookie、session、缓存与代理
- Xcode7.2 使用NSURL发送http请求报错
- 网络流GAP dinic模板
- 网络 HTTP协议
- 同或门(XNOR)电路的网络学习
- iOS网络编程4--使用SwiftyJSON解析JSON数据
- 24篇HTTP博客
- 常见HTTP状态码(200、301、302、500等)解说
- System.ServiceModel.CommunicationException: 接收HTTP 响应时错误发生
- HTTP协议 (1)初识HTTP
- HttpClient和DefaultHttpClient