Parse a URI String into Name-Value Collection

前端 未结 19 2746
难免孤独
难免孤独 2020-11-22 01:34

I\'ve got the URI like this:

https://google.com.ua/oauth/authorize?client_id=SS&response_type=code&scope=N_FULL&access_type=offline&redirect_         


        
19条回答
  •  离开以前
    2020-11-22 02:10

    org.apache.http.client.utils.URLEncodedUtils

    is a well known library that can do it for you

    import org.apache.hc.client5.http.utils.URLEncodedUtils
    
    String url = "http://www.example.com/something.html?one=1&two=2&three=3&three=3a";
    
    List params = URLEncodedUtils.parse(new URI(url), Charset.forName("UTF-8"));
    
    for (NameValuePair param : params) {
      System.out.println(param.getName() + " : " + param.getValue());
    }
    

    Outputs

    one : 1
    two : 2
    three : 3
    three : 3a
    

提交回复
热议问题