Android使用OkHttp发送帖子请求

  

本文实例为大家分享了使用OkHttp发送帖子请求的具体代码,供大家参考,具体内容如下

  

MainActivity.java         公开课MainActivity延伸AppCompatActivity {      私人EditText mEt_qq;   私人EditText mEt_pwd;   私人TextView mTv_status;      字符串路径=" http://169.254.53.96:8080/web/LoginServlet”;      私有静态最终int成功=665;   私有静态最终int=894;      处理程序处理程序=new处理程序(){   @Override   公共空间handleMessage(消息味精){   开关(msg.what) {   成功案例:   字符串文字=(字符串)msg.obj;   mTv_status.setText(文本);   打破;   案例下降:   Toast.makeText (MainActivity。这个,”没有网”,Toast.LENGTH_SHORT),告诉();   打破;   默认值:   打破;   }   }   };      @Override   保护空白>   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android:取向=按怪薄?   android: paddingBottom=" @dimen/activity_vertical_margin”   android: paddingLeft=" @dimen/activity_horizontal_margin”   android: paddingRight=" @dimen/activity_horizontal_margin”   android: paddingTop=" @dimen/activity_vertical_margin”   工具:上下文="。祝辞MainActivity”;      EditText & lt;   android: id=癅 + id/et_qq”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:提示="请输入qq号码”/比;      EditText & lt;   android: id=癅 + id/et_pwd”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:提示="请输入密码”   android: inputType=" textPassword "/比;      & lt;按钮   android: onClick="登录"   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:文本="登陆”/比;         & lt; TextView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: id=癅 + id/tv_status”   android:文本="登陆状态:“/比;      & lt;/LinearLayout>      

构建。gradle//依赖

        实现“com.squareup.okhttp3: okhttp: 3.4.2”      

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

Android使用OkHttp发送帖子请求