![](/img/trans.png)
[英]Unable to pass data to a POST request using Volley library - Android
[英]Unable to post data to api from android using Volley
我想使用post方法注册用户。 这是API链接:
`http://125.62.194.181/SmartTrackerAPI/api/User/SignUp/UserName/EmpId/Email/Mobile/Password`
我是JSON的新手。 我了解如何从JSON获取数据,但是涉及到POST方法时,我却没有怎么做?
需要帮助,谢谢。
通过POST发送到服务器的数据存储在HTTP请求的请求主体中:
这是一个如何使用Volley It的示例:-
String url = "YOUR URL";
RequestQueue queue = Volley.newRequestQueue(this);//Creating The Request Queue
StringRequest postRequest = new StringRequest(Request.Method.POST/*Setting The Method As Post*/, url/*Passing The Url Of Your API*/,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// response
Log.d("Response", response);
//Here You Will Get Your JSON as response.
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", response);
//Here You Will Get Your Error related to your Request.
}
}
) {
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("name", "Alif");
params.put("domain", "http://itsalif.info");//Puting The Parameters In Map To Pass It To The API.
return params;
}
};
queue.add(postRequest);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.