我的休息时间有问题。我使用的是Volley库,但结果与浏览器android中的响应不同?
这是,URL =
https://assac.com/profilepicture?app_key=bpHANRATGW35hkHNMJA9ssMOnLog9l7l3IxXDGiv&session_key=LSDK4ARF0w8flNc8GCj8mvvKdctKnN68FKSKlKplhyAClNK2&page=1&limit=10
和java中的这种格式
String url = Variabel.URL_PHOTO_PROFILE + "?app_key=" + URLEncoder.encode(Variabel.app_key) + "&session_key=" + URLEncoder.encode(session_key)
+ "&page=" + String.valueOf(Variabel.page) + "&limit="
+ Variabel.LIMIT_DATA;
完整代码:
private void getNewAllPhotoUserFromServer() {
String url = Variabel.URL_PHOTO_PROFILE + "?app_key=" + Variabel.app_key + "&session_key=" + session_key
+ "&page=" + String.valueOf(Variabel.page) + "&limit="
+ Variabel.LIMIT_DATA;
Log.v("new", url);
queue_get_new_all_photo_user = Volley.newRequestQueue(getActivity());
sr_get_all_new_photo_user = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
DrawDataAllPhotoUser(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof NetworkError) {
messageRespone("Koneksi bermasalah");
} else if (error instanceof ServerError) {
messageRespone("Server Error");
} else if (error instanceof AuthFailureError) {
messageRespone("Koneksi Timeout");
} else if (error instanceof ParseError) {
messageRespone("Ada masalah dalam mengambil data");
} else if (error instanceof NoConnectionError) {
messageRespone("Tidak ada koneksi");
} else if (error instanceof TimeoutError) {
messageRespone("Koneksi Timeout");
}
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> jsonParams = new HashMap<String, String>();
return jsonParams;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
sr_get_all_new_photo_user.setRetryPolicy(new DefaultRetryPolicy(
Variabel.MY_SOCKET_TIMEOUT_MS_NEWS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue_get_new_all_photo_user.add(sr_get_all_new_photo_user);
}
java的结果是:
{
"isSuccess": true,
"message": "ok",
"pageCurrent": "1",
"pageTotal": 1,
"itemsTotal": 2,
"memberProfilePictures": [
{
"photoMemberId": "O6lXnljaVabh55dd08c87b59c55dd08c87b64255dd08c87b6e4e5cAv",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 1,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_08_26/1440549064367_medium.png",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_08_26/1440549064367_large.png",
"photoMemberWidth": 480,
"photoMemberHeight": 700
},
{
"photoMemberId": "QNRiYnQKk8V755d931c44efcd55d931c44f07155d931c44f11efffVd",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 0,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_08_23/14402974122618_medium.jpeg",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_08_23/14402974122618_large.jpeg",
"photoMemberWidth": 480,
"photoMemberHeight": 269
}
]
}
但浏览器的结果是:
{
"isSuccess": true,
"message": "ok",
"pageCurrent": "1",
"pageTotal": 1,
"itemsTotal": 4,
"memberProfilePictures": [
{
"photoMemberId": "kmz9RnqQmi2I55f7bc9eb023955f7bc9eb02df55f7bc9eb0381v2PqG",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 0,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_09_15/14422990385762_medium.jpeg",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_09_15/14422990385762_large.jpeg",
"photoMemberWidth": 480,
"photoMemberHeight": 640
},
{
"photoMemberId": "O6lXnljaVabh55dd08c87b59c55dd08c87b64255dd08c87b6e4e5cAv",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 1,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_08_26/1440549064367_medium.png",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_08_26/1440549064367_large.png",
"photoMemberWidth": 480,
"photoMemberHeight": 700
},
{
"photoMemberId": "QNRiYnQKk8V755d931c44efcd55d931c44f07155d931c44f11efffVd",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 0,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_08_23/14402974122618_medium.jpeg",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_08_23/14402974122618_large.jpeg",
"photoMemberWidth": 480,
"photoMemberHeight": 269
},
{
"photoMemberId": "WwJHWP9ZQWhr55f7bc849ecec55f7bc849ed9055f7bc849ee41P6Ebd",
"photoMemberIdMember": "LWC6MZOgIZxB559c5af5ca70c559c5af5ca7b2559c5af5ca855TiMPZ",
"photoMemberStatus": 0,
"photoMemberURL": "https://assac.com/public/uploads/pictures/2015_09_15/14422990125018_medium.jpeg",
"photoMemberURLLarge": "https://assac.com/public/uploads/pictures/2015_09_15/14422990125018_large.jpeg",
"photoMemberWidth": 480,
"photoMemberHeight": 853
}
]
}
那么如何解决呢?
答案 0 :(得分:0)
由于您的Variabel.LIMIT_DATA
似乎是2
,所以答案是不同的。将其设置为10
(因为它在您的网址中),您应该有相同的结果(可能不是相同的顺序)。