UrlEncoder编码的字符串不起作用?

时间:2017-03-03 10:54:09

标签: android url encoding

你好我必须在get方法url中传递json,因为我已经使用了改造库。

http://jbossdev- ***** ***** COM / **** /网络/休息/ waitlistRestAction / checkinusers ORGID = 2及pagerReqParam = { “过滤器”。?NULL,“排序“:NULL,” 中将sortOrder “:空” 的pageSize “:500,” 您做生意“:1}

我想编码json { “过滤器”:空, “排序”:NULL, “中将sortOrder”:空 “的pageSize”:500, “您做生意”:1}

正确编码:

http://jbossdev- ***** ***** COM / kyobee /网络/休息/ waitlistRestAction / checkinusers ORGID = 2及pagerReqParam =%7B%22filters%。22:?空,%22sort% 22:空,%22sortOrder%22:空,%22pageSize%22:500,%22pageNo%22:1%7D

我在url中传递编码字符串后得到的内容

http://jbossdev- ***** ***** COM / ***** /网络/休息/ waitlistRestAction / checkinusers ORGID = 2&安培;?pagerReqParam =%257B%2522filters%2522%253Anull %252C%2522sort%2522%253Anull%252C%2522sortOrder%2522%253Anull%252C%2522pageSize%2522%253A500%252C%2522pageNo%2522%253A1%257D

  @GET(General.CHECK_IN_USERS)
    Call<CheckInUsers> checkInUsers (@Query(ORG_ID) String orgId , @Query(PAGER_REQ_PARAM) String pagerReqParam);


 String query = URLEncoder.encode (reqParam, "WINDOWS-1252");           
            mAPIService = General.getClient ().create (APIService.class);
            Call<CheckInUsers> checkInUsersCall = mAPIService.checkInUsers (orgId, query);
            checkInUsersCall.enqueue (new Callback<CheckInUsers> (){
                @Override
                public void onResponse (Call<CheckInUsers> call, Response<CheckInUsers> response){
}

1 个答案:

答案 0 :(得分:0)

如果您已实现类似于此的接口,请尝试使用encoded = true获取所需参数

示例:

public interface APIInterface {

    @GET ("loginapi.php")
    @Headers({"Content-Type: application/x-www-form-urlencoded"})
    Call<LoginPOJO> loginResponse(
                                    @Query(value = "password",encoded = true) String password,
                                    @Query(value = "key",encoded = true) String key,
                                    @Query(value = "uid",encoded = true) String uid,
                                    @Query(value = "email", encoded = true) String email
                                 );
}