[英]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.