Android-凌空请求在模拟器上工作,但在电话上不作用
在过去的几天里,这一直在发生。我们有一个jsonobjectRequest:
public Map<String,String> loginUser(String uemail, String upassword, final AuthAsyncResponse callBack) {
String url = "https://our.url/auth/signin";
Map<String,String> userData = new HashMap<>();
final HashMap<String, String> postParams = new HashMap<String, String>();
postParams.put("email", uemail);
postParams.put("password", upassword);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Request.Method.POST,
url,
new JSONObject(postParams),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String status = response.getString("status");
Log.d(TAG, "login status: " + response);
if (status.equals("Success")) {
// Work with data and set up userData object
} else {
//Log.d("Log", "onResponse: available" + status);
userData.put("status", status);
}
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, "login status: ", e);
}
if (null != callBack) callBack.processFinished(userData);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("LOG", "onErrorResponse: " + error);
}
}
)
{
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
AppController.getInstance().getRequestQueue().getCache().clear();
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
return userData;
}
如果我在模拟器上运行它,则一切正常。
但是,截至几天前,如果我从设备运行它,我会收到一个超时错误。
看来,在整个应用程序中,即使直到上周才能使用JSONOBJECTREQUESTS,也没有在设备上工作。因此,即使已经发布的应用程序也无法再加载数据。
我已经用Postman测试了URL,这很好。我们只是不知道是什么原因导致设备上的错误。
更新:经过进一步的测试,我们发现问题不是凌空,而是URL。如果我们将URL代替另一个URL,则一切都可以。但是,此确切的URL确实在iOS和Postman以及Android模拟器中起作用。正是通过Android设备提出请求的时候,这不起作用。
This has been happening over the last couple days. We have a JsonObjectRequest:
public Map<String,String> loginUser(String uemail, String upassword, final AuthAsyncResponse callBack) {
String url = "https://our.url/auth/signin";
Map<String,String> userData = new HashMap<>();
final HashMap<String, String> postParams = new HashMap<String, String>();
postParams.put("email", uemail);
postParams.put("password", upassword);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Request.Method.POST,
url,
new JSONObject(postParams),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String status = response.getString("status");
Log.d(TAG, "login status: " + response);
if (status.equals("Success")) {
// Work with data and set up userData object
} else {
//Log.d("Log", "onResponse: available" + status);
userData.put("status", status);
}
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, "login status: ", e);
}
if (null != callBack) callBack.processFinished(userData);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("LOG", "onErrorResponse: " + error);
}
}
)
{
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
AppController.getInstance().getRequestQueue().getCache().clear();
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
return userData;
}
If I run this on the simulator, everything works fine.
However as of a couple days ago, if I run it from the device, I get a Timeout error.
It appears that across the whole app, no JsonObjectRequests are working on the device, even though they were until last week. Even the app version that was already published can't load data anymore because of this.
I have tested the URL with Postman and it's working fine. We just don't know what is causing this error on the device.
UPDATE: After further testing we've found out that the issue is not Volley but the URL. If we substitute the URL for a different one, everything works. However this exact URL does work on both iOS and Postman and in the Android simulator. It's just when the request is made from an Android device that this doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论