【发布时间】:2020-01-28 04:53:30
【问题描述】:
我有 laravel 网站,我想为这个网站创建 android 应用程序 我是java初学者。
总结...
对于身份验证 api 路由,我使用一个中间件。 这个中间件有一个令牌。 在邮递员计划中,一切都很好...... 但是当我想在 volley android 中发送一个带有标头令牌的帖子请求时 我的函数不能给出用户名或一些变量...
请帮我解决这个问题 这是我的功能 send volly ,不要忘记邮递员请求中的一切都是好的
int selectedId = statusregister.getCheckedRadioButtonId();
radioselect=(RadioButton)findViewById(selectedId);
send=0;
String url="my http api site...";
requestQueue= Volley.newRequestQueue(RegisterActivity.this);
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("response",response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("HttpClient", "error: " + error.toString());
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>(); params.put("username",username.getText().toString().trim());
params.put("email",mailuser.getText().toString().trim());
params.put("password",password.getText().toString().trim());
params.put("status",radioselect.getText().toString().trim());
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params2 = new HashMap<String, String>();
params2.put("Content-Type", "application/json; charset=UTF-8");
params2.put("APP_KEY", "7ACFdsd328BEA81sssdfgg556B91");
return params2;
}
};
requestQueue.add(stringRequest);
}
401 错误... 当我删除中间件时就可以了...
这是在标题中设置 APP_KEY 的屏幕截图 enter image description here
以及在标题中设置 APP_KEY 后的截图 enter image description here
【问题讨论】:
-
请编辑您的问题并添加邮递员请求参数的屏幕截图
标签: laravel android-volley http-token-authentication