Android 使用HttpGet进行登录
发布日期:2021-06-30 22:35:01
浏览次数:2
分类:技术文章
本文共 1262 字,大约阅读时间需要 4 分钟。
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(); } }}
转载地址:https://lovoo.blog.csdn.net/article/details/51223569 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月25日 04时06分56秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Django + REST学习笔记
2019-04-30
【转载】将Ubuntu16.04 中gedit在仅显示一个文件时显示文件名tab
2019-04-30
fstream 对象多次使用时注意clear
2019-04-30
调试 LenaCV 3D Camera (Linux)
2019-04-30
OpenCV杂记 - Mat in C++
2019-04-30
lnmp部署
2019-04-30
location区段
2019-04-30
nginx访问控制、基于用户认证、https配置
2019-04-30
SaltStack
2019-04-30
linux内存的寻址方式
2019-04-30
ubunut16.04的pip3出现问题,重新安装pip3
2019-04-30
how2heap-double free
2019-04-30
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30