3
我想知道如何在登录请求的URL是Android的凌空图书馆
username:password http://login_url
这种格式发送凌空登录请求。如果有示例代码可用,这将非常有帮助。 的目的是将登录请求发送到基于django框架的网站。
在此先感谢
我想知道如何在登录请求的URL是Android的凌空图书馆
username:password http://login_url
这种格式发送凌空登录请求。如果有示例代码可用,这将非常有帮助。 的目的是将登录请求发送到基于django框架的网站。
在此先感谢
首先创建一个字符串的请求 - >>
StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
});
那么,你应该覆盖getParams()方法的方法!
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put(KEY_USERNAME,username);
params.put(KEY_PASSWORD,password);
params.put(KEY_EMAIL, email);
return params;
将请求添加到请求队列!
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
三个简单的步骤:)
随意问任何疑问
试试这个
// Tag used to cancel the request
String tag_json_obj = "json_obj_req";
String url = "http:login_url";
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//your response
Log.d(TAG, response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", "username");
params.put("email", "[email protected]");
params.put("password", "password123");
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
你能告诉我你做了什么??? – alway5dotcom
curl -H“Content-Type:application/json”-X POST -d {“email”:“[email protected]”,“first_name”:“FName”,“last_name”:“Lname”,“password” :“pass123”}'http://192.xxx.xxx.xxx:1111/register_user/ 这是我应该如何将值传递给服务器..任何人可以帮助我..这是怎么可能使用凌空? –