我这边采用xutlis3请求
整体界面是这样的

布局是这样的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAFAFA"
tools:context=".activity.LogActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/dp_324"
android:src="@mipmap/sample_image" />
<RelativeLayout
android:id="@+id/ttop"
android:layout_width="@dimen/dp_355"
android:layout_height="@dimen/dp_249"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_133"
android:background="@drawable/card_style">
<TextView
android:id="@+id/tv_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_20"
android:text="账户"
android:textColor="#203152"
android:textSize="@dimen/sp_14" />
<EditText
android:inputType="phone"
android:id="@+id/et_phon"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_below="@id/tv_acc"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:hint="输入电话号码"
android:textColor="#ff203152"
android:textSize="@dimen/sp_16" />
<TextView
android:id="@+id/tv_phon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et_phon"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_20"
android:text="验证码"
android:textColor="#203152"
android:textSize="@dimen/sp_14" />
<EditText
android:inputType="textPassword"
android:id="@+id/et_yanzhengma"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_below="@id/tv_phon"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:hint="输入验证码"
android:textColor="#ff203152"
android:textSize="@dimen/sp_16" />
<TextView
android:id="@+id/bt_yz"
android:background="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_phon"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/dp_20"
android:text="获取验证码"
android:textColor="#007AFF"
android:textSize="@dimen/sp_11" />
<Button
android:id="@+id/btn_login"
android:layout_width="@dimen/dp_295"
android:layout_height="@dimen/dp_55"
android:layout_below="@id/et_yanzhengma"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_30"
android:background="@drawable/ca_style"
android:text="登陆"
android:textColor="@color/white"
android:textSize="@dimen/sp_19" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ttop"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_20"
android:text="提示:钓鱼易账户免注册,可使用手机号、微信号直接登录"
android:textColor="#9D9D9D"
android:textSize="@dimen/sp_11" />
<ImageView
android:id="@+id/iv_wx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ttop"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_153"
android:src="@mipmap/wx" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/iv_wx"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_13"
android:text="微信登录"
android:textColor="@color/black"
android:textSize="@dimen/sp_15"
android:textStyle="bold" />
<TextView
android:textColor="#007AFF"
android:layout_marginTop="@dimen/dp_42"
android:layout_below="@id/iv_wx"
android:text="《用户使用协议》《隐私协议》"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="@dimen/sp_11" />
</RelativeLayout>
代码是这样的
package com.example.isfishing.activity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.example.isfishing.BuildConfig;
import com.example.isfishing.R;
import com.example.isfishing.api.Api;
import com.example.isfishing.bean.Phone;
import com.google.gson.Gson;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LogActivity extends AppCompatActivity implements View.OnClickListener {
private int countSeconds = 60;//倒计时秒数
private EditText et_number, et_code;
private Button btn_code, btn_start;
private Context mContext;
private String usersuccess;
private Handler mCountHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (countSeconds > 0) {
--countSeconds;
btn_code.setText("(" + countSeconds + ")后获取验证码");
mCountHandler.sendEmptyMessageDelayed(0, 1000);
} else {
countSeconds = 60;
btn_code.setText("请重新获取验证码");
}
}
};
private String userinfomsg;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_log);
x.Ext.init(getApplication());
x.Ext.setDebug(BuildConfig.DEBUG);//
initView();
initEvent();
initData();
}
private void initView() {
et_number = (EditText) findViewById(R.id.et_number);//手机号
btn_code = (Button) findViewById(R.id.btn_code);//获取验证码
et_code = (EditText) findViewById(R.id.et_code);//验证码
btn_start = (Button) findViewById(R.id.btn_start);//登陆
}
private void initEvent() {
btn_code.setOnClickListener(this);
btn_start.setOnClickListener(this);
}
private void initData() {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_code:
if (countSeconds == 60) {
String mobile = et_number.getText().toString();
Log.e("tag", "mobile==" + mobile);
getMobiile(mobile);
} else {
Toast.makeText(LogActivity.this, "不能重复发送验证码", Toast.LENGTH_SHORT).show();
}
break;
case R.id.btn_start:
login();
break;
default:
break;
}
}
/**
* 简要描述
* 手机号码登录接口
* 请求URL
* /user/MobileLogin
* 请求方式
* POST
* 参数
* 参数名 必选 类型 说明
* Mobile 是 string 手机号
* Code 是 string 验证码
* 返回示例
* {
* "Total": 0,
* "Data": {
* "UserId": 217308907641507840,
* "UserStatus": 1,
* "IsOnline": 1,
* "UserName": "wsdz123",
* "RealName": "万世电子管理员",
* "WebToken": "8ee02a069fd74edf83777d4f9dd682c4",
* "ApiToken": "f969cf8df66f4ab8860a9af071783434",
* "IsSystem": 0,
* "Portrait": "http://thirdwx.qlogo.cn/mmopen/vi_32/KCww10GA18iboEhkTnQPjO3ZmtAwqHzsGuVGGAlcticIVGoeKujUDSUDico8u99ibicNeoFaUpwlsVGaJf87nFiawG4A/132",
* "DepartmentId": 217308032248320000,
* "DepartmentName": "万世电子",
* "PositionIds": null,
* "RoleIds": "16508640061130146"
* },
* "Tag": 1,
* "Message": "登录成功",
* "Description": null,
* "Remarks": null
* }
* 返回参数说明
* 参数名 类型 说明
* Tag int -2:验证码不存在或过期;-1:验证码错误;0:绑定失败;1:绑定成功
* Message string 提示文案与上面内容一致
*/
private void login() {
String mobile = et_number.getText().toString().trim();
String verifyCode = et_code.getText().toString().trim();
RequestParams params = new RequestParams("http://api.idiaoyuyi.com/user/MobileLogin");
params.setBodyContentType("application/json");
params.addBodyParameter("Mobile",mobile);
params.addParameter("Code",verifyCode);
x.http().post(params, new Callback.ProgressCallback<String>() {
@Override
public void onSuccess(String result) {
try {
JSONObject jsonObject = new JSONObject(result);
Log.e("tag", "登陆的result=" + jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
@Override
public void onWaiting() {
}
@Override
public void onStarted() {
}
@Override
public void onLoading(long total, long current, boolean isDownloading) {
}
});
}
//获取验证码信息,判断是否有手机号码
private void getMobiile(String mobile) {
if ("".equals(mobile)) {
Log.e("tag", "mobile=" + mobile);
new AlertDialog.Builder(mContext).setTitle("提示").setMessage("手机号码不能为空").setCancelable(true).show();
} else if (isMobileNO(mobile) == false) {
new AlertDialog.Builder(mContext).setTitle("提示").setMessage("请输入正确的手机号码").setCancelable(true).show();
} else {
Log.e("tag", "输入了正确的手机号");
requestVerifyCode(mobile);
}
}
/**
* 简要描述
* 发送短信
* 请求URL
* /user/SendMessage
* 请求方式
* POST
* 参数
* 参数名 必选 类型 说明
* Mobile 是 string 手机号码
* MsgType 是 int 1、会员中心绑定手机号获取验证码;2手机号登录验证码
* 返回示例
* {
* "Tag": 1,
* "Message": "短信已发出,请注意查收",
* "Description": null,
* "Remarks": null
* }
* 返回参数说明
* 参数名 类型 说明
* Tag int 1 发送成功,其他状态失败,有提示文案(手机号码格式错误/短信发送太频繁了)
* @param mobile
*/
private void requestVerifyCode(String mobile) {
RequestParams requestParams = new RequestParams("http://api.idiaoyuyi.com/user/SendMessage");
requestParams.setBodyContentType("application/json");
requestParams.addBodyParameter("Mobile",mobile);
requestParams.addParameter("Code","2");
x.http().post(requestParams, new Callback.ProgressCallback<String>() {
@Override
public void onWaiting() {
}
@Override
public void onStarted() {
}
@Override
public void onLoading(long total, long current, boolean isDownloading) {
}
@Override
public void onSuccess(String result) {
try {
JSONObject jsonObject = new JSONObject(result);
Log.e("tag", "验证码的result=" + jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
});
}
//使用正则表达式判断电话号码
public static boolean isMobileNO(String tel) {
Pattern p = Pattern.compile("^(13[0-9]|15([0-3]|[5-9])|14[5,7,9]|17[1,3,5,6,7,8]|18[0-9])\\d{8}$");
Matcher m = p.matcher(tel);
System.out.println(m.matches() + "---");
return m.matches();
}
//获取验证码信息,进行计时操作
private void startCountBack() {
((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
btn_code.setText(countSeconds + "");
mCountHandler.sendEmptyMessage(0);
}
});
}
}
请求结果是这样的

我裂开了!谁能帮忙解决下。。。。
代码里面有接口 有说明
postman中,如果我body什么都不传递,就是提示415.
你这个传参是存放body的。我尝试body传递,有结果。
先不写代码呀,用postMan模拟请求一下,成功了再去写代码。
况且log已经提示你了,不支持的媒体类型415。