80,337
社区成员
发帖
与我相关
我的任务
分享
OkHttpUtils
.postString()
.url(url)
.content(new Gson().toJson(new PhoneBean(phone)))
.build()
.....
PhoneBean是需要传递的数据的类
public class PhoneBean{
private String phone_number;
public PhoneBean(String phone_number) {
this.phone_number= phone_number;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number= phone_number;
}
}
如果有多个参数,就添加多个参数并设置值进行传递fun register(
context: Context,
email: String,
password: String,
complete: (Boolean) -> Unit) {
val jsonBody = JSONObject()
jsonBody.put("email", email)
jsonBody.put("password", password)
val requestBody = jsonBody.toString()
val registerRequest = object : StringRequest(
Method.POST,
URL_REGISTER,
Response.Listener { response ->
println(response)
complete(true)
},
Response.ErrorListener { error ->
Log.d("ERROR", "Could not register user")
complete(false)
}) {
override fun getBodyContentType(): String {
return "application/json; charset=utf-8"
}
override fun getBody(): ByteArray {
return requestBody.toByteArray()
}
}
Volley.newRequestQueue(context).add(registerRequest)
}
fun register(
context: Context,
email: String,
password: String,
complete: (Boolean) -> Unit) {
val jsonBody = JSONObject()
jsonBody.put("email", email)
jsonBody.put("password", password)
val requestBody = jsonBody.toString()
val registerRequest = object : StringRequest(
Method.POST,
URL_REGISTER,
Response.Listener { response ->
println(response)
complete(true)
},
Response.ErrorListener { error ->
Log.d("ERROR", "Could not register user")
complete(false)
}) {
override fun getBodyContentType(): String {
return "application/json; charset=utf-8"
}
override fun getBody(): ByteArray {
return requestBody.toByteArray()
}
}
Volley.newRequestQueue(context).add(registerRequest)
}