Java 无法在Android中发送简单的HTTPS请求(截取)
背景:我试图向HTTPS API发出请求,询问客户机是否已经注册。 问题:为什么RequestQueue永远不工作Java 无法在Android中发送简单的HTTPS请求(截取),java,android,request,android-volley,Java,Android,Request,Android Volley,背景:我试图向HTTPS API发出请求,询问客户机是否已经注册。 问题:为什么RequestQueue永远不工作 RequestQueue queue = Volley.newRequestQueue(this); StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, new Response.Listener<String>() { @Overrid
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
System.out.println("ggg:"+response);
if (response.contains("HERE")) {
Toast.makeText(getApplicationContext(), "Logged in successfully!", Toast.LENGTH_LONG).show();
Intent in = new Intent(getApplicationContext(), ImportContactsActivity.class);
startActivity(in);
} else if (response.contains("OK")) {
Toast.makeText(getApplicationContext(), "Not", Toast.LENGTH_LONG).show();
} else if (response.contains("logoff")) {
Toast.makeText(getApplicationContext(), "Please log off your old device to login.", Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//sSystem.out.println("bla: "+error);
}
});
queue.add(stringRequest);
RequestQueue queue=Volley.newRequestQueue(this);
StringRequest StringRequest=新的StringRequest(Request.Method.GET,URL,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
//显示响应字符串的前500个字符。
System.out.println(“ggg:+响应);
if(response.contains(“此处”)){
Toast.makeText(getApplicationContext(),“成功登录!”,Toast.LENGTH\u LONG.show();
Intent in=newintent(getApplicationContext(),ImportContactsActivity.class);
星触觉(in);
}else if(response.contains(“OK”)){
Toast.makeText(getApplicationContext(),“Not”,Toast.LENGTH_LONG.show();
}else if(response.contains(“注销”)){
Toast.makeText(getApplicationContext(),“请注销旧设备以登录。”,Toast.LENGTH_LONG).show();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//sSystem.out.println(“bla:+错误);
}
});
添加(stringRequest);
我还在浏览器中测试了相同的URL,不到一秒钟就得到了响应
您是否在“AndroidManifest.xml”中请求了android.permission.INTERNET的
权限?@StuStirling是的,因为我还有其他使用HTTPS的部分可以工作。好吧,我想这太容易了。我想你也不会因为截击而出错吧?你能看到网络请求通过Charles或Android Profiler进入API吗/确保请求方法正确。i、 你能补充你的问题吗?