[英]how to pass web api(post request) url parameters as requestbody in android using okhttp
I have a asp.net web api url which accepts query string parameters but its actually a post request. 我有一个asp.net Web API URL,它接受查询字符串参数,但实际上是一个发布请求。 I am trying to access the same url in android but not sure how to pass the query parameters.
我正在尝试在android中访问相同的url,但不确定如何传递查询参数。 Any help will be appreciated as I am not an android developer basically.
任何帮助将不胜感激,因为我基本上不是Android开发人员。
Here is the snippet: 这是代码段:
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();
This is the solution: 这是解决方案:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.