您可以直接从String URL使用create URI:List listOfParameters = ...;URI uri = new URIBuilder("http://example.com:8080/path/to/resource?mandatoryParam=someValue")
.addParameter("firstParam", firstVal)
.addParameter("secondParam", secondVal)
.addParameters(listOfParameters)
.build();
否则,您可以显式指定所有参数:URI uri = new URIBuilder()
.setScheme("http")
.setHost("example.com")
.setPort(8080)
.setPath("/path/to/resource")
.addParameter("mandatoryParam", "someValue")
.addParameter("firstParam", firstVal)
.addParameter("secondParam", secondVal)
.addParameters(listOfParameters)
.build();
一旦创建了URI对象,那么您只需创建HttpGet对象并执行它://create GET requestHttpGet httpGet = new HttpGet(uri);//perform requesthttpClient.execute(httpGet ...//additional parameters, handle response etc.