python与android交互,Android客户端与Python服务器端的简单通信

本文介绍了如何使用OkHttp在Android客户端与Python Flask服务器端实现简单通信。在Android端,通过OkHttp发送用户输入的用户名和密码到服务器,服务器端使用Flask接收并处理数据,返回相应的响应信息。示例代码包括Android的MainActivity.java和服务器端的userpwd.py。
摘要由CSDN通过智能技术生成

最近在做一个APP,需要与服务器通信,一点一点的尝试,记录一下。

本文使用了OkHttp和Flask框架。

Android客户端:

实现功能输入完点击OK按钮后会toast成功的信息。

fee8e5f79b96f5520908fd3aa7ac2473.png

3b67baeb24743b800a468b353835833d.png

Python服务端:

e1e75cb3a44143cc6562c80af40055c6.png

各部分代码如下:

activity_main.xml:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity">

android:id="@+id/username"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:hint="username" />

android:id="@+id/password"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:hint="password" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值