我有一个asp.net web api url,它接受查询字符串参数但实际上是一个post请求。我试图在Android中访问相同的URL,但不知道如何传递查询参数。任何帮助将不胜感激,因为我基本上不是Android开发人员。
以下是摘录:
RequestBody formBody = new FormBody.Builder()
.add("email", mEmail.toLowerCase())
.add("password", mPassword)
.build();
//2. Bind the request Object
Request req = new Request.Builder()
.url(loginAPI).post(formBody)
.build();
Response response = client.newCall(req).execute();
答案 0 :(得分:0)
这是解决方案:
String loginAPI = "http://api.myapi.com/api/authentication?email="+mEmail.toLowerCase()+"&password="+mPassword;
RequestBody reqbody = RequestBody.create(null, new byte[0]);
Request req = new Request.Builder()
.url(loginAPI)
.method("POST", reqbody)
.build();
Response response = client.newCall(req).execute();