Java HttpClient:错误:com.android.volley.RedirectError loginBtn.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图) { 字符串userName=editTextEmail.getText().toString().trim(); 字符串密码editTextPassword.getText().toString().trim(); 字符串登录\u URL=”http://www.someurl.com/Rest/AIwebservice/Authenticate?user=“+userName+”&password=“+password; //字符串uri=String.format(“https://www.auruminfo.com/Rest/AIwebservice/Authenticate?user=subhash&password=Subhash"); //字符串uri=String.format(“https://www.someurl.com/Rest/AIwebservice/Authenticate?user=“+userName+”&password=“+password”); StringRequest sr=newStringRequest(Request.Method.GET,LOGIN\uURL, 新的Response.Listener(){ @凌驾 公共void onResponse(字符串响应){ Log.e(“HttpClient”,“success!response:+response.toString()); } },new Response.ErrorListener(){ @凌驾 公共无效onErrorResponse(截击错误){ Log.e(“HttpClient”,“error:error.toString()); } }) { @凌驾 受保护的映射getParams(){ Map params=新的HashMap(); 参数put(“用户”,“用户”); 参数put(“密码”,“密码”); 返回参数; } @凌驾 公共映射getHeaders()引发AuthFailureError{ Map params=新的HashMap(); 参数put(“内容类型”,“应用程序/json;字符集=UTF-8”); 返回参数; } }; 添加(sr); } }); }
和日志目录:- 08-02 18:17:08.778 7070-7091/com.some.eww.logindemo E/Volley:[9414]BasicNetwork.performRequest:请求已重定向到 08-02 18:17:08.794 7070-7070/com.anghatechsolution.eww.logindemo E/HttpClient:error:com.android.volley.errorJava HttpClient:错误:com.android.volley.RedirectError loginBtn.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图) { 字符串userName=editTextEmail.getText().toString().trim(); 字符串密码editTextPassword.getText().toString().trim(); 字符串登录\u URL=”http://www.someurl.com/Rest/AIwebservice/Authenticate?user=“+userName+”&password=“+password; //字符串uri=String.format(“https://www.auruminfo.com/Rest/AIwebservice/Authenticate?user=subhash&password=Subhash"); //字符串uri=String.format(“https://www.someurl.com/Rest/AIwebservice/Authenticate?user=“+userName+”&password=“+password”); StringRequest sr=newStringRequest(Request.Method.GET,LOGIN\uURL, 新的Response.Listener(){ @凌驾 公共void onResponse(字符串响应){ Log.e(“HttpClient”,“success!response:+response.toString()); } },new Response.ErrorListener(){ @凌驾 公共无效onErrorResponse(截击错误){ Log.e(“HttpClient”,“error:error.toString()); } }) { @凌驾 受保护的映射getParams(){ Map params=新的HashMap(); 参数put(“用户”,“用户”); 参数put(“密码”,“密码”); 返回参数; } @凌驾 公共映射getHeaders()引发AuthFailureError{ Map params=新的HashMap(); 参数put(“内容类型”,“应用程序/json;字符集=UTF-8”); 返回参数; } }; 添加(sr); } }); },java,android,Java,Android,和日志目录:- 08-02 18:17:08.778 7070-7091/com.some.eww.logindemo E/Volley:[9414]BasicNetwork.performRequest:请求已重定向到 08-02 18:17:08.794 7070-7070/com.anghatechsolution.eww.logindemo E/HttpClient:error:com.android.volley.error 我在我的案例中的字符串LOGIN_URL=“”中发现了问题
我在我的案例中的字符串LOGIN_URL=“”中发现了问题
原始API使用的是HTTPS而不是HTTP我在String LOGIN_URL=“”中发现了这个问题
原始API使用HTTPS而不是HTTP检查您的后端代码AUthentication@MrCurious你是说WebService检查你的后端代码AUthentication@MrCurious你是说网络服务
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
String userName = editTextEmail.getText().toString().trim();
String password editTextPassword.getText().toString().trim();
String LOGIN_URL = "http://www.someurl.com/Rest/AIwebservice/Authenticate?user="+userName+"&password="+password;
//String uri = String.format("https://www.auruminfo.com/Rest/AIwebservice/Authenticate?user=subhash&password=Subhash");
//String uri = String.format("https://www.someurl.com/Rest/AIwebservice/Authenticate?user="+userName+"&password="+password);
StringRequest sr = new StringRequest(Request.Method.GET,LOGIN_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("HttpClient", "success! response: " + response.toString());
}
},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("user","");
params.put("password","");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/json;charset=UTF-8");
return params;
}
};
queue.add(sr);
}
});
}